index.html 876 B

12345678910111213141516171819202122232425262728
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>
  5. Static File Index.HTML
  6. </title>
  7. <script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js'></script>
  8. </head>
  9. <body>
  10. <div id='formContainer'>
  11. <input id="nick" placeholder="nick" value="nick">
  12. <input id="message" placeholder="text" value="msg">
  13. <button id="btn">Send</button>
  14. </div>
  15. <script>
  16. const socket = io()
  17. socket.on('msg', msg => {
  18. let p = document.createElement('p');
  19. p.innerHTML = `${msg.nick} : ${msg.message}`;
  20. document.body.appendChild(p);
  21. });
  22. btn.onclick = () => {
  23. socket.emit('msg', {nick: nick.value, message: message.value});
  24. } ;
  25. </script>
  26. </body>
  27. </html>