Here is a little trick that should work. First, you create your own Socket client, which sends a message on the first connection (containing all your additional information).
// Client side io.MySocket = function(your_info, host, options){ io.Socket.apply(this, [host, options]); this.on('connect', function(){ this.send({__special:your_info}); }); }; io.util.inherit(io.MySocket, io.Socket); var my_info = {a:"ping"} var socket = io.MySocket(my_info);
Then, on the server side, you modify your socket to listen for a special message and fire an event when it does.
// Server side var io = require('socket.io').listen(app); io.on('connection', function(client){ client.on('message', function(message){ if (message.__special) { io.emit('myconnection', client, message.__special); } }); }); io.on('myconnection', function(client, my_info) { // Do your thing here client.on('message', ...); // etc etc }
This is the method I used to bind session processing to Socket.IO for the package I wrote.
source share