How to best send additional data upon socket connection?
Client:
socket.on(\'connect\',function(){
//I\'d like set some values and pass them up to t
I have a different approach - emit an event right after connecting, with the data:
socket.on('connect',function(){
// Send ehlo event right after connect:
socket.emit('ehlo', data);
});
io.on('connection', function(client){
// Receive ehlo event with data:
client.on('ehlo', function(data) {
});
});
You can hold a variable/object, and say, when there is no ehlo event with data, the other events are ignored until ehlo is sent.
If this does not satisfy, you can send data right when connecting, I won't copy the code but it is in this answer: https://stackoverflow.com/a/13940399/1948292