Reputation: 331
I have implemented a websocket server which acts as observer for some events.
@ServerEndPoint
public class Server implements SomeObserver
I have implemented objectChanged() from SomeObserver class. The objectChanged() will execute when there is some event will be occur. It is common observer implemnetation.
The application logic is like this: Clients connect to Websocket server and server sends appropriate events for appropriate clients.
I have coded it like this:
@ServerEndPoint
public class Server implements SomeObserver
{
Session clientSession = null;
@OnOpen
public void OnOpen(Session session}
{
clientSession = session;
}
//implemented OnMessage and OnClose, OnError methods
public void objectChanged(Event[] event)
{
clientSession.sendAsyncRemote().sendObject(someObjectInfo);
}
I never used any session identification. But surprisingly, server sends appropriate messages for respective session. Server does not send one sessions event to another session without any session authentication or identification.
Does anyone know why and how it happens in Tyrus API. I want to know how Tyrus webocket support session identification.
Upvotes: 0
Views: 435
Reputation: 1
clientSession.sendAsyncRemote().sendObject(someObjectInfo);
In the above line, the session object will be created per connection basis. It holds the reference socket object (per connection).
Hence, when message is sent, data will be transferred to the respective client.
Upvotes: -1