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

Hi,

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?

Yes.

> 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 http://wiki.eclipse.org/Jetty/Feature/WebSockets 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.

See https://github.com/eclipse/jetty.project/blob/master/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java.

Or, you can look at CometD for a simpler way to use WebSocket
features: http://cometd.org.

Simon
-- 
http://cometd.org
http://intalio.com
http://bordet.blogspot.com
----
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