Advertisement
Guest User

Untitled

a guest
Aug 5th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. var restify = require('restify');
  2. var socketio = require('socket.io');
  3.  
  4. var server = restify.createServer();
  5.  
  6. server.get('/', function (req, res, next) {
  7. res.json(204, null);
  8. io.emit("sample", {"sample":"event"});
  9. next();
  10. });
  11.  
  12. server.listen(8080, function () {
  13. console.log('socket.io server listening at %s', server.url);
  14. });
  15.  
  16. <!doctype html>
  17. <html lang="en">
  18. <head>
  19. <meta charset="UTF-8">
  20. <title>Socket.IO Chat Example</title>
  21. </head>
  22. <body>
  23. <script src="socket.io.js"></script>
  24. <script type="text/javascript">
  25. var socket = io.connect('http://localhost:8080');
  26. socket.on('sample', function (data) {
  27. console.dir(data);
  28. });
  29. </script>
  30. </body>
  31. </html>
  32.  
  33. socket.io:server initializing namespace / +0ms
  34. socket.io:server creating engine.io instance with opts {"path":"/socket.io"} +3ms
  35. socket.io:server attaching client serving req handler +1ms
  36. socket.io server listening at http://0.0.0.0:8080
  37. socket.io:server incoming connection with id U9hLZRlbsGfvI8QPAAAA +2s
  38. socket.io:client connecting to namespace / +4ms
  39. socket.io:namespace adding socket to nsp / +0ms
  40.  
  41. http.js:690
  42. throw new Error('Can't set headers after they are sent.');
  43. ^
  44. Error: Can't set headers after they are sent.
  45. at ServerResponse.OutgoingMessage.setHeader (http.js:690:11)
  46. at ServerResponse.format (/home/vagrant/socket.io-server-example/node_modules/restify/lib/response.js:109:10)
  47. at ServerResponse.send (/home/vagrant/socket.io-server-example/node_modules/restify/lib/response.js:231:24)
  48. at emitRouteError (/home/vagrant/socket.io-server-example/node_modules/restify/lib/server.js:152:13)
  49. at onRoute (/home/vagrant/socket.io-server-example/node_modules/restify/lib/server.js:610:21)
  50. at Router.find (/home/vagrant/socket.io-server-example/node_modules/restify/lib/router.js:512:5)
  51. at Server._route (/home/vagrant/socket.io-server-example/node_modules/restify/lib/server.js:604:21)
  52. at routeAndRun (/home/vagrant/socket.io-server-example/node_modules/restify/lib/server.js:572:14)
  53. at Server._handle (/home/vagrant/socket.io-server-example/node_modules/restify/lib/server.js:592:9)
  54. at Server.onRequest (/home/vagrant/socket.io-server-example/node_modules/restify/lib/server.js:255:14)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement