Skip to content

Instantly share code, notes, and snippets.

@pifantastic
Created June 7, 2011 01:19
Show Gist options
  • Save pifantastic/1011489 to your computer and use it in GitHub Desktop.
Save pifantastic/1011489 to your computer and use it in GitHub Desktop.
var express = require('express'),
io = require('socket.io'),
// Map clients to sessions by IP
clients = {};
var app = express.createServer();
app.use(express.cookieParser());
app.use(express.session({ secret: "keyboard cat" }));
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(3000);
var socket = io.listen(app);
socket.on('connection', function(){
// New client.
clients[client.request.socket.remoteAddress] = client.sessionID;
client.on('message', function(){
var session = getSession(client);
});
client.on('disconnect', function(){ … });
});
function getSession(client) {
var sid = clients[client.request.socket.remoteAddress];
return socket.clients
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment