Skip to content

How do I send a message to a single client? #1

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

Closed
ghost opened this issue Aug 18, 2010 · 2 comments
Closed

How do I send a message to a single client? #1

ghost opened this issue Aug 18, 2010 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 18, 2010

I'm looking at the ChatServer.java example

I see how you can send a message to all web clients using the sendToAll(String) function, but how does one send to just a single web client?

It's not coming up in my Eclipse autocomplete.

Many thanks in advance,

@TooTallNate
Copy link
Owner

You need to call send(String) on an individual WebSocket instance to send an individual message. These are retrieved as the first parameter from any of the onOpen, onClose or onMessage callbacks, or via the connections property on the WebSocketServer instance.

Perhaps it would be helpful to add a convenience function to the WebSocketServer class: send(WebSocket, String)?

I urge you to look at the precompiled JavaDoc files inside the doc folder inside the repo for any more API questions.

@ghost
Copy link
Author

ghost commented Aug 19, 2010

Hey,

Thanks for your reply. Yes, I get a WebSocket object every time onClientOpen(conn) gets called. I then copy this object and can send to an individual browser. It's all working now. Sorry for the schoolboy error. I'm just back to Java after many years of programming in C.

Good project. So much cleaner and more straightforward than jWebSocket which has a crazy website. You provide one jar for the WebSocket server and one jar for the javadocs. Perfect.

threat pushed a commit that referenced this issue Aug 13, 2015
Make @threat's acceptance tests actually usable
marci4 added a commit that referenced this issue Mar 22, 2017
marci4 pushed a commit that referenced this issue Jan 19, 2020
suggested fix for issue 665 "data read at end of SSL handshake is discarded"
marci4 pushed a commit that referenced this issue Jan 19, 2020
marci4 pushed a commit that referenced this issue Mar 25, 2022
Issue-1160 Added java.lang.Error handling in WebSocketImpl and WebSocketServer
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

1 participant