A library to make working with websockets easier.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.html 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>SockSugar</title>
  5. </head>
  6. <body>
  7. <input type="text" id="url" value="ws://localhost:8081">
  8. <button id="connect">Connect</button>
  9. <div id="message"></div>
  10. <script src="../client.js"></script>
  11. <script>
  12. document.getElementById("connect").addEventListener("click", function() {
  13. var url = document.getElementById("url").value;
  14. //Create a new SockSugar socket
  15. window.sock = new SockSugar(url);
  16. window.sock.on("ready", function() {
  17. document.getElementById("message").innerHTML =
  18. "Connected! You can now play with the global "+
  19. "'sock' object in a JavaScript console. "+
  20. "Try doing <code>sock.send('myMsg', ...)</code>, "+
  21. "or typing <code>send</code> in the server's console.";
  22. //Listen to 'myEvent', which the server emits when you
  23. //type 'send' in its console
  24. sock.on("myEvent", function(data) {
  25. console.log("Received myEvent from server!");
  26. console.log(data);
  27. });
  28. sock.on("close", function() {
  29. document.getElementById("message").innerHTML =
  30. "Connection closed!";
  31. });
  32. });
  33. });
  34. </script>
  35. </body>
  36. </html>