Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server socket id doesn't match client's socket id #2405

Closed
stgogm opened this issue Jan 25, 2016 · 10 comments
Closed

Server socket id doesn't match client's socket id #2405

stgogm opened this issue Jan 25, 2016 · 10 comments

Comments

@stgogm
Copy link

stgogm commented Jan 25, 2016

For some reason, after upgrading to 1.4.4, the sockets on the server return the socket.id property as /#BA0yIQhFb5R55OnvAAAC but in the client as BA0yIQhFb5R55OnvAAAC.

This inconsistency has broken one of my apps. Am I doing something wrong?

@nkzawa
Copy link
Contributor

nkzawa commented Jan 29, 2016

That was changed on 1.4.0. Maybe we should change socket.id on client to the same format with server. cc @rauchg

You can use socket.client.id on server for now, which would be matched with client's socket.id.

@stgogm
Copy link
Author

stgogm commented Jan 29, 2016

Thanks, but I think this behavior breaks functionality and if you installed socket.io via npm and it's defined as "^1.3.6", for example, it'll definitively break your app if you rely on socket.id to achieve some functionality.

One more thing, if now socket.id is not equal to socket.client.id that means that when you want to emit a message to a specific socket it'll be sent to both socket.id and socket.client.id?

@smcardle
Copy link

smcardle commented Feb 1, 2016

I also have this issue.

The server side pre-pends the default namespace but the client does not.
This has caused me SERIOUS issues with our app after an upgrade. We missed 1.4.0 and went straight to 1.4.4.
It's good to know that socket.client.id on the server side is the same as the client side id.

However, a fix for this would be good....

I also noticed a few other issues with this upgrade..

  1. Counting the number of sockets in a room
    My original code was a follows :

            var numClients = 0;
            var clients = sio.sockets.adapter.rooms["test"];
            if(clients)  {
                numClients = Object.keys(clients).length;
            }
    

    i.e. sio.sockets.adapter.rooms[data.room] returned an array containing the socket ids of the sockets that had joined the "test" room

After this upgrade sio.sockets.adapter.rooms["test"] now returns a Room object that contains an array called sockets that contains the socket ids instead, requiring a change to the code as follows

            var numClients = 0;
            var room = sio.sockets.adapter.rooms["test"];
            if(room)  {
                numClients = Object.keys(room.sockets).length;
            }
  1. socket.io-redis DOES NOT WORK with this version as broadcasting and emitting events to clients in a room does not result in any of those clients receiving a message.
    However, emitting to the self i.e. socket.emit(...) does work.

Any chance these issues will be resolved soon ???

Steve

@LordMajestros
Copy link

@smcardle Socket.io-redis works for me but I had to update to 1.0.0 check your version.

@stgogm
Copy link
Author

stgogm commented Feb 2, 2016

Although this changes are improvements they shouldn't be considered minor as they break a lot of functionality. Please consider that the node environment, specially npm, always relies on semver and this changes doesn't respect that at all.

@ilanbiala
Copy link

Hey guys, how is this going to be fixed? @rauchg any thoughts?

@smcardle
Copy link

OK so I finally got back to testing a few things and I am pretty pissed that the changes in this version are HUGE and should have really been released as version 2.x.x

As @LordMajestros pointed out socket.io-redis 1.0.0 does work with this version so that at least is something.

The rest of the changes including changes to the old and new meanings or broadcast as well the introduction of the Room object verses the sockets hash for a room caused me many many issues until all affected functionality was eventually converted

Steve

@nkzawa
Copy link
Contributor

nkzawa commented Apr 10, 2016

@ilanbiala We are going to change socket.id on client to the same format with server, which should solve the problem.

@darrachequesne
Copy link
Member

That issue was closed automatically. Please check if your issue is fixed with the latest release, and reopen if needed (with a fiddle reproducing the issue if possible).

@lucasbiel7
Copy link

ty @nkzawa @stgogm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@nkzawa @smcardle @stgogm @ilanbiala @LordMajestros @darrachequesne @lucasbiel7 and others