Question: I am trying implement a Websocket connection taking an example from here - <https://gist.github.com/chitan/3063774>.
This is a echo server.
My question is - 
How can i take a message from a particular user and send it to another user instead of echoing to the same user.
I have searched a lot and most of the examples i have found are Echo examples.

Answer: 
In Java EE7, you can do that easily. Think about an simple example. If you write `client.getBasicRemote().sendObject(message);` in a method with `@OnMessage` annotation than it will be available only active client session.

```
@ServerEndpoint("/websocket")
public class ChatEndpoint {
    @OnMessage
    public void message(String message, Session client) throws IOException, EncodeException {

            client.getBasicRemote().sendObject(message); 

    }
}

```

if you loop the message on client.getOpenSessions() then it will be available to all clients:

```
   @OnMessage
public void message(String message, Session client) throws IOException, EncodeException      {
    for (Session peer : client.getOpenSessions()) {
        peer.getBasicRemote().sendObject(message); 
    }
}

```

For details, go to this [tutorial](http://docs.oracle.com/javaee/7/tutorial/doc/websocket.htm).
If you still need to use Java 6 and `WebSocketServlet` you can do something like this:

```
public class WsChatServlet extends WebSocketServlet{

    public StreamInbound createWebSocketInbound(String protocol){
        MyMessageInbound ms = new MyMessageInbound();
        // store ms somewhere and than find it and use getWsOutbound() to respond
        return ms;
    }
 ...
}

```