Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] WebSockets: Specific Client Message


On Tue, Jan 10, 2012 at 15:30, Hendrik Schenk <hschenk@xxxxxxx> wrote:
> hi,
> I have 2 questions:
> 1. Is there an opportunity to send a message from server to a specific
> client which is connected to server?


> 2. At the moment, i use a servlet fpr the communication between the clients
> and the server. Is there another way to communicate with the websockets
> server? I mean, i need a interface where the clients can connect to and send
> and retrieve messages.

See as a starting point.

What you need is to extend WebSocketServlet and implement doWebSocketConnect().

That method is invoked for each remote client connection.
You should return an implementation of a WebSocket sub-interface, most
often WebSocket.OnTextMessage.
This object is linked with the remote client and allows you to handle
passive events (i.e. events generated by the remote client).

To generate events you can use the WebSocket.Connection API. You
obtain an instance of this interface in WebSocket.onOpen() and you can
use it to send messages and close the connection.


Or, you can look at CometD for a simpler way to use WebSocket

Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz

Back to the top