Has anyone successfully implemented a dynamic namespace in node/socket.io?

Go To StackoverFlow.com

3

Meaning: A user auth's to an application -> application sets the namespace of the socket.io connection (http://www.socketioserver.com/NAMESPACE) and the node server responds accordingly without being hard-coded for that particular namespace. to that particular namespace.

The purpose is therefore to write one piece of server-side node code that responds to requests for a particular namespace with the appropriate data for that namespace without knowing what namespace is going to connect from the client before hand.

2012-04-04 03:41
by EvilJordan


3

Yes you can do this pretty easily. You'll just need to perform some kind of a handshake (eg. send a message on the default ns with something used to identify the requested ns) beforehand, so that the socketio code knows what namespace it needs to listen on.

You can then just use sio.of(namespaceFromHandshake).on...

2012-04-04 08:13
by Jani Hartikainen
Ah. I was overthinking. Thanks - EvilJordan 2012-04-04 13:13
I know I'm responding to this many months later... At the time, using a very old version of node, this worked. I cannot, for the life of me, make it work with the latest versions of node and socket.io - EvilJordan 2012-11-26 18:34
Ads