GeeCON Prague 2014*
The moose likes Scala and the fly likes WebSockets in Play and Scala - Suggestion needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Languages » Scala
Bookmark "WebSockets in Play and Scala - Suggestion needed" Watch "WebSockets in Play and Scala - Suggestion needed" New topic
Author

WebSockets in Play and Scala - Suggestion needed

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9394
    
    2

I'm not sure if this is the right forum to ask my question. I have a client that I wrote using Scala and the Play framework. It is a WebSocket client that creates a WebSocket connection and keeps it open to send about 20000 messages roughly in Json format. The server processes these messages and sends back Json responses. How is the WebSocket client supposed to handle the responses from the client? The server sends the responses asynchronously and the client registers a handler which in turn receives the messages from the server. Is the onMessage handler in the client called sequentially for each message that gets sent from the server? Any ideas?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42030
    
  64
I've never used WebSockets, so take this with a grain of salt, but I am quite sure that if either side sends 20K messages, there is a better architecture to do it. That does not sound like a scenario WebSockets are meant to address.


Ping & DNS - my free Android networking tools app
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9394
    
    2

Ulf Dittmer wrote:I've never used WebSockets, so take this with a grain of salt, but I am quite sure that if either side sends 20K messages, there is a better architecture to do it. That does not sound like a scenario WebSockets are meant to address.


What is that better architecture? I'm a bit curious to know about it! The motivation to use a WebSocket is that the client and server would require to exchange messages via TCP frequently and there is no bandwidth to create a new connection everytime. I'm just trying to apply load on the WebSocket connection and see how the server and the client behave under such conditions.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42030
    
  64
So you have not actually tried the scenario that you're worrying about, and it is just a test scenario to begin with?

The motivation to use a WebSocket is that ... there is no bandwidth to create a new connection everytime.

If there is a bandwidth issue then any communication will have problems. WebSockets are meant to address server-to-client communication (which generally is not possible with HTTP), and improve on latency (by not having to open a new connection for each message).
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9394
    
    2

Can you please throw some light on the other architecture that you were mentioning? That would probably give me some ideas!
Ivano Pagano
Ranch Hand

Joined: Dec 16, 2006
Posts: 47

Ulf Dittmer wrote:If there is a bandwidth issue then any communication will have problems. WebSockets are meant to address server-to-client communication (which generally is not possible with HTTP), and improve on latency (by not having to open a new connection for each message).


There's more to that: the throughput of a websocket connection is a concrete improvement over the HTTP protocol, whose heavier payload (headers are sent with every communication) can become burdensome if you have a frequent exchange of small bits of content.
Joe's design could be the right solution, if the pure http scenario is verified as being too slow.

I too am curious about alternative designs.
Bye, Ivano
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9394
    
    2

The WebSocket end points proved valuable to us in achieving a better throughput. I like the idea and combining this with a non-blocking server like Netty is for me the way to go.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: WebSockets in Play and Scala - Suggestion needed