How can I send extra parameters with the connection in socket.io? So when a client connects, they send additional information, and server-side it is received as
io.on('connection', function(client, param1, param2, param3) {
// app code
}
Once you reboot your machine, you will now be able to happily go to 55k concurrent connections (per incoming IP).
"The Socket.IO server currently has some problems with scaling up to more than 10K simultaneous client connections when using multiple processes and the Redis store, and the client has some issues that can cause it to open multiple connections to the same server, or not know that its connection has been severed."
Load benchmarks Here we can see that the HTTP benchmark peaks at about~950 requests per second while Socket.io serves about ~3900 requests per second.
Both Pusher Channels and socket.io allow you to publish and subscribe to messages in realtime using the WebSocket protocol. The main difference is that Channels is a hosted service/API, and with socket.io you need to manage the deployment yourself.
Here's a little trick which should work. First, you create your own Socket client that sends a message on first connection (containing all your additional info).
// 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 the special message and fire off 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 technique I used to link my session handling into Socket.IO for a package I wrote.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With