Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.86 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <html>
  2. <head>
  3.   <script src="/socket.io/socket.io.js"></script>
  4. </head>
  5. <body>
  6. <div id="output"></div>
  7. <script>
  8. function write (msg) {
  9.   var p = document.createElement('p');
  10.   p.innerHTML = 'LOG: ' + msg;
  11.   document.getElementById('output').appendChild(p);
  12. };
  13. var socket = io.connect();
  14. socket.on('connect', function () {
  15.   write('<strong>CONNECT EVENT CALLED</strong>');
  16.  
  17.   socket.emit('print', 'foo');
  18.   socket.emit('print', 'bar');
  19. });
  20.  
  21. socket.on('connecting', function (transport) {
  22.   write('Trying to connect using ' + transport);
  23. });
  24.  
  25. socket.on('disconnect', function () {
  26.   write('Aww, disconnected');
  27. });
  28.  
  29. socket.on('reconnecting', function (delay, attempt) {
  30.   write('reconnecting, attempt #' + attempt);
  31. });
  32.  
  33. socket.on('reconnect', function () {
  34.   write('reconnected <3');
  35. })
  36.  
  37. /*socket.on('done', function () {
  38.   socket.disconnect();
  39. });*/
  40.  
  41. </script>
  42. </body>
  43. </html>