Play framework 2.5.0 Websockets example [closed]

半世苍凉 提交于 2019-12-04 20:57:12

问题


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.


回答1:


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, ?>
})


来源:https://stackoverflow.com/questions/36168515/play-framework-2-5-0-websockets-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!