Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Last active December 16, 2015 06:59
Show Gist options
  • Save 3rd-Eden/5395511 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/5395511 to your computer and use it in GitHub Desktop.
simple socket htingy
var http = require('http');
var server = http.createServer(function (req, res) {
res.statusCode = 200;
res.end('<script src="/socket.io/socket.io.js"></script>');
});
var io = require('socket.io').listen(server);
io.sockets.on('connection', function (socket) {
socket.emit('hi');
socket.on('ping', function () { socket.emit('pong') });
});
server.listen(8080);
@3rd-Eden
Copy link
Author

For bonus points type:

x = io.connect(); x.on('pong', function () { console.log('pong'); setTimeout(function () { x.emit('ping') }, 2000); }); x.emit('ping');

in your console after you have opened your browser on http://localhost:8080.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment