For a websocket request, there are 2 phases:
1. The websocket request comes in as a normal HTTP request, you have
everything like session data, cookie etc.
2. If you decide to accept (upgrade) the normal HTTP request, the
connection will be kept. Because there's phase 1, at phase 2 you have
everything you need.
I'm not familiar with the API of Play, but in Xitrum there's
"acceptWebSocket" method. If you decide to go to phase 2, you call
this method. Otherwise you treat the request as normal HTTP request,
e.g. you can send normal HTTP response to the client.
https://github.com/ngocdaothanh/xitrum-demos/blob/master/src/main/scala/demos/controller/WebSocketChat.scala
http://ngocdaothanh.github.com/xitrum/guide/async.html#websocket
On May 27, 12:52 am, will <
william.bes...@gmail.com> wrote:
> Hi,
>
> There's something I don't really get.
>
> How to associate both websockets and sessions to push specific data to a
> specific client.
>
> Let's imagine a private message system where people can send messages
> (stored in DB) to each other, each client having its own account. One
> client sends a message to another client.
>
> The fact this user has sent a message could trigger the event "hey, you've
> received a message from this guy, click here to read it".
>
> But how *not* to send this event to ALL connected clients ? And how to make
> it work so it could do "the user with ID 123 has sent (understand "has
> recorded inside a DB") the message with ID 666 to the user with ID 456 (you
> !!!), so let's broadcast to the websocket of the user 456 (you!!!) the
> event that the message 666 has been sent to him and is available for
> reading pointing to the URLhttp://domain/readmymessage?id=666".