Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var restify = require('restify');
- var socketio = require('socket.io');
- var server = restify.createServer();
- server.get('/', function (req, res, next) {
- res.json(204, null);
- io.emit("sample", {"sample":"event"});
- next();
- });
- server.listen(8080, function () {
- console.log('socket.io server listening at %s', server.url);
- });
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Socket.IO Chat Example</title>
- </head>
- <body>
- <script src="socket.io.js"></script>
- <script type="text/javascript">
- var socket = io.connect('http://localhost:8080');
- socket.on('sample', function (data) {
- console.dir(data);
- });
- </script>
- </body>
- </html>
- socket.io:server initializing namespace / +0ms
- socket.io:server creating engine.io instance with opts {"path":"/socket.io"} +3ms
- socket.io:server attaching client serving req handler +1ms
- socket.io server listening at http://0.0.0.0:8080
- socket.io:server incoming connection with id U9hLZRlbsGfvI8QPAAAA +2s
- socket.io:client connecting to namespace / +4ms
- socket.io:namespace adding socket to nsp / +0ms
- http.js:690
- throw new Error('Can't set headers after they are sent.');
- ^
- Error: Can't set headers after they are sent.
- at ServerResponse.OutgoingMessage.setHeader (http.js:690:11)
- at ServerResponse.format (/home/vagrant/socket.io-server-example/node_modules/restify/lib/response.js:109:10)
- at ServerResponse.send (/home/vagrant/socket.io-server-example/node_modules/restify/lib/response.js:231:24)
- at emitRouteError (/home/vagrant/socket.io-server-example/node_modules/restify/lib/server.js:152:13)
- at onRoute (/home/vagrant/socket.io-server-example/node_modules/restify/lib/server.js:610:21)
- at Router.find (/home/vagrant/socket.io-server-example/node_modules/restify/lib/router.js:512:5)
- at Server._route (/home/vagrant/socket.io-server-example/node_modules/restify/lib/server.js:604:21)
- at routeAndRun (/home/vagrant/socket.io-server-example/node_modules/restify/lib/server.js:572:14)
- at Server._handle (/home/vagrant/socket.io-server-example/node_modules/restify/lib/server.js:592:9)
- 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