1

So I'm connecting two variable (objects) to the same socket.io server, one's job is to handle public feed and another's to handle private feed with extended functions.

I've attempted the "force new connection" option, however both connections seem to still use utilize the same socket + session Id.

I originally didn't include code because this is so basic, but here you go:

var socket = io(host);
socket.on('connect', function(e){
    socket.emit('join', {
        channel: stream_channel,
    });
});

One is var socket, the other is var socket2. When it connects to the server it emits "join" where:

io.on('connection', function(socket){
    socket.on('join', function(d){
        socket.join(d.channel);
    });
});
2
  • Show us your code please. The problem is with your specific code, not with socket.io in general. As I would think you would know from your experience here, questions about code should always include the relevant code as that will always get you a better and more specific answer and in some cases (like this) is the only way to get an answer that isn't just a wild guess.
    – jfriend00
    Aug 5, 2015 at 5:05
  • 1
    FYI, session IDs are likely cookie based so two connections from the same client will always share the same cookies and thus share the same session ID (if they are indeed cookie based). But, the correct code will create two separate socket.io connections if desired.
    – jfriend00
    Aug 5, 2015 at 5:08

1 Answer 1

0

I was able to figure this out by:

  1. Subscribing the websocket to multiple rooms
  2. Appending additional variables at each POST to define the room to emit to

I was able to determine that:

  1. Utilizing the same host will always keep the same session id / socket (even with force connection enabled)
  2. Potentially using a different host or namespace would allow a separation in connection
  3. It's better to keep a single connection with multiple rooms

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.