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

Allow multiple listeners to be bound to a server #12

Closed
johnboxall opened this issue May 17, 2010 · 3 comments
Closed

Allow multiple listeners to be bound to a server #12

johnboxall opened this issue May 17, 2010 · 3 comments

Comments

@johnboxall
Copy link

I've have two distinct types of connections coming at my server - it would seem the easiest way to separate them would be to bind create two io.listeners and change the resource of each connection type - however in the current implementation in Listener.init will just grab the last Listener bound to the server!

p.s Fantastic piece of software!

@johnboxall
Copy link
Author

Meant to leave this on Socket.IO-node

@rauchg
Copy link
Contributor

rauchg commented May 17, 2010

Are you saying you have two HTTP servers, or you have two widgets that need realtime connectivity in the same page? If the answer is the latter, you have to build a small protocol on top of a single io.Listener to channel the messages.

At LearnBoost, we built a simple channel-subscription model tied to server side and client side event listeners, so that we can have several independent flows of communication, but with only 1 transport initialization per client.

@johnboxall
Copy link
Author

I'm working on a remote JavaScript debugger - on one page, you've got a console. On the other page the debugger is running.

Whenever a debugger connects it opens a new channel. Consoles connect to a debugger channel to receive messages. Debuggers send messages to all connected consoles.

I could use conditional logic inside the connection/message event listeners, it would seem more DRY to create multiple listeners and have the correct one fire by inspecting the "resource".

io.listen(server, {
    resource: "socket.io.console",
    onClientMessage: function(message, client){
        sys.puts("Client Message!");
    }
});

io.listen(server, {
    resource: "socket.io.debugger",
    onClientMessage: function(message, client){
        sys.puts("Debugger Message!");
    }
});

// Vs.

io.listen(server, {
    onClientMessage: function(message, client){
        if (message.type == "client"){
            sys.puts("Client Message!");
        } else{
            sys.puts("Debugger Message!");        
    }
});

// ++ Extra logic in the client for constructing the message.

rauchg pushed a commit that referenced this issue Apr 12, 2016
This issue was closed.
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

2 participants