Skip to content

Instantly share code, notes, and snippets.

@rogerdudler
Created August 19, 2011 08:44
Show Gist options
  • Save rogerdudler/1156354 to your computer and use it in GitHub Desktop.
Save rogerdudler/1156354 to your computer and use it in GitHub Desktop.
Socket.io usage in Node.js
// create an http server listening on port 8000
var io = require('socket.io').listen(8000);
// listen on new connections
io.sockets.on('connection', function (socket) {
// listen on an event called "eventA"
socket.on('eventA', function(data) {
// send "eventA" to all clients, except the sender
io.sockets.emit('eventA', data);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment