Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
socket.io/server
var fs = require('fs');
var server = require('http').createServer(handler);
var io = require('socket.io').listen(server);
function handler (req, res) {
if (req.url === '/') {
res.statusCode = 200;
res.setHeader('content-type', 'text/html');
fs.createReadStream('./index.html').pipe(res);
}
}
io.sockets.on('connection', function (socket) {
socket.on('echo', function (data) {
io.sockets.emit('echo', data, socket.username);
});
socket.on('setName', function (name) {
socket.username = name;
io.sockets.emit('join', name);
});
});
server.listen(8080);
@dscape

This comment has been minimized.

Copy link

dscape commented Aug 8, 2012

Private gists would be better imho :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.