Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play framework 2.5.0 Websockets example [closed]

Play framework 2.5.0 Websockets example.

in play 2.5.0 websockets code is changed to support akka streams but I'm not able find a sample code to use it.

like image 387
Chandan Pasunoori Avatar asked Mar 23 '16 01:03

Chandan Pasunoori


Video Answer


1 Answers

This will be properly documented in 2.5.1 as you can see here: https://github.com/playframework/playframework/issues/5057


In the meantime you can take a look at the Migration Guide which has a part on Streams: https://www.playframework.com/documentation/2.5.x/StreamsMigration25#Migrating-WebSockets-%28WebSocket%29

You will notice that the important part is the WebSocket.MappedWebSocketAcceptor<In,Out> class. You use this one to tell Play how to convert Message frames to your own types - like String, Json, etc.

Fortunately the Java API of Play provides some predefined implementations. Let's say you want to handle WebSocket connections which exchange JSON data. Then you would use WebSocket.Json (https://github.com/playframework/playframework/blob/master/framework/src/play/src/main/java/play/mvc/WebSocket.java#L71)

return WebSocket.Json.accept(requestHeader -> {
  // returns a Flow<JsonNode, JsonNode, ?>
})
like image 98
Anton Avatar answered Oct 12 '22 04:10

Anton