2013-12-18 72 views
4

處理Websockets時,我拿着netty's client和一個使用Scala(2.10.2)使用Play Framework(2.2.1)構建的服務器(代碼粘貼在下面)。 服務器對客戶端的Ping消息沒有反應。既不接收任何傳入Ping消息的Iteratee通知,也不會響應Ping消息。Play Framework Websocket服務器不處理來自netty客戶端的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) 
} 
+0

我發現關於播放[這裏]的WebSocket平幀的進一步討論(https://groups.google.com/forum/#!searchin/play-framework/websocket $ 20ping /播放框架/ D3veSt-Cv3Y/hgsXiT5lfDsJ) – Finnfalter

回答

相關問題