处理Websockets,我使用
Scala(2.10.2)使用Play Framework(2.2.1)构建了
netty’s client和服务器(下面粘贴的代码).服务器不会对客户端的Ping消息做出反应.既没有Iteratee通知任何传入的Ping消息,框架本身也没有响应Ping消息.
但是,我的应用程序处理传入的二进制帧这看起来很奇怪,因为in Netty’s code,二进制帧与Ping帧非常相似.我所知道的唯一区别是OpCode,即Ping为0x9,Binay为0x2.
任何人都可以解释这种行为,并给我一个提示如何处理Play框架中的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)
}
最佳答案 Playframework不支持pingframe.它完全忽略了它.现在这是在master中修复的