Play Framework Websocket服务器不处理来自netty客户端的Ping帧

时间:2013-12-18 13:25:17

标签: scala playframework websocket netty

处理Websockets,我使用Scala(2.10.2)使用Play Framework(2.2.1)构建了netty's client和服务器(下面粘贴的代码)。 服务器不会对客户端的Ping消息做出反应。既不会通知Iteratee任何传入的Ping消息,也不会使Framework本身响应Ping消息。

但是,我的应用程序处理传入的二进制帧。这看起来很奇怪,因为in Netty's code,二进制帧与Ping帧非常相似。我所知道的唯一区别是OpCode,即Ping为0x9,Binay为0x2。

任何人都可以解释这种行为并给我一个提示如何处理Play Framework中的Websocket Ping / Pong帧吗?

def connect = WebSocket.using[Array[Byte]] { request =>
   // connection attempts are also indicated if client sends 'PingWebSocketFrame'
   Logger.info("Someone just connected!?")

   val (out, channel) = Concurrent.broadcast[Array[Byte]]

   // Messages of netty's type 'PingWebSocketFrame' never enter here
   val in = Iteratee.foreach[Array[Byte]] { msg =>
      // the following line is printed if netty's 'BinaryWebSocketFrame' was sent BUT
      //                         never if netty's 'PingWebSocketFrame'   was sent, why?
      println("Some Binary data arrived, being of length " + msg.length + " [bytes]")
   }
(in, out)
}

1 个答案:

答案 0 :(得分:2)

Playframework不支持pingframe。它完全忽略了它。现在这已在主人

中修复

https://github.com/playframework/playframework/pull/2130