0
votes

I am looking at the websocket-chat example. It unveils much, but I still cannot get something. I understand how messages are received, processed and sent on the web page side.

However, Play captures websocket messages by means of the receive method of an Akka actor. In the websocket-chat, there are several cases in this method, but I don't get, how does it know which websocket message should be mapped to which case. In fact, I don't understand the path that a websocket message follows upon entering Play's domain, how is it processed and how can different message types/kinds be sent from the webpage.

I have not find any info or sources related to this. Could please someone explain this or point to some kind of a good reference?

UPDATE:

The link to the original example.

1
@nico_ekito I did not write any code yet, I am stuck studying the very basic example. The example of the websocket chat application is included in the standard package of Play framework. If you download and install it, you can get it running. And it is also available online, see the update to the original post. - noncom
But what particular part of this code do you not understand ? The controller ? The Actor ? - ndeverge
@niko_ekito I think I understand the code, what I do not understand - is how websocket messages received from the webpage are automatically associated with the Talk case class? Is it possible for the webpage to emit messages that will be associated with different case classes? I do not understand the mechanism.. and maybe I am totally wrong, but why the messages from the webpage do not get processed by other cases in the CharRoom actor and instead are processed in that particular case??? - noncom

1 Answers

2
votes

The receive method from the sample doesn't have any link to the Play Websocket API. This receive method comes from the Akka library.

The Websockets events are managed through an Iteratee, which create and send a Talk message to the Actor system.

Simply put, it allows to have a highly scalable system (non-blocking), by sending messages between "workers".

So I suggest that you take a look at the Actor model in the Akka library.