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

Channel message dispatching issue #182

Closed
asotog opened this issue May 23, 2013 · 3 comments
Closed

Channel message dispatching issue #182

asotog opened this issue May 23, 2013 · 3 comments

Comments

@asotog
Copy link

asotog commented May 23, 2013

Hi,

First at all, great component, was doing some tests with multiple clients but noticed some things for example, if some clients are connected to ws://x.x.x.x:8090/news and there are another clients connected to ws://x.x.x.x:8090/actions, all the clients will listen the same messages, so my question is, is there any way to isolate both group of clients, so group of news can listen only news and so on with actions group,

Thanks,

@Davidiusdadi
Copy link
Collaborator

Please excuse my late answer.

Yes, you have total control which client will see which messages - you write the server - you have control over all connections. Via onMessage you know which client sent which messages to the server. Based on that information you can decide to which client you "forward" it ( by calling WebSocket.send )

You can iterate through the connected clients by iterating over WebSocketServer.connections() in synchronized manner. Like this:

Collection<WebSocket> con = connections();
    synchronized ( con ) {
        for( WebSocket c : con ) {
            // put your special condition here
               c.send( "text" );
        }
}

Currently its not very comfortable to obtain the resource descriptor ( "/news"). One has to make use of a WebSocketFactory and deriving from WebSocketImpl to create a function that returns the resource descriptor...

Since i think that what you ask for is a rather common case i will add a getResourceDescriptor() method to the WebSocket class which allows you to easily find out which resource descriptor was used the in websocket handshake.

Feel free to ask if you have further questions.

Davidiusdadi added a commit that referenced this issue Jun 4, 2013
getResourceDescriptor do the WebSocket interface. #182
@Davidiusdadi
Copy link
Collaborator

After pulling you should be able to do something like this:

Collection<WebSocket> con = connections();
    synchronized ( con ) {
        for( WebSocket c : con ) {
            if( c.getResourceDescriptor().equals("/news") )
                c.send( "this is new" );
        }
}

@asotog
Copy link
Author

asotog commented Jun 5, 2013

Awesome man looks pretty good, thanks so much

@asotog asotog closed this as completed Jun 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants