while true do local data, typ, err = _self.ws:recv_frame() if not data then local bytes, err = _self.ws:send_ping() if not bytes then ngx.log(ngx.ERR, "failed to send ping: ", err) conn_abort_handler(_self) return ngx.exit(444) end elseif typ == "close" then conn_abort_handler(_self) _self.ws:send_close(1000) ngx.exit(200) elseif typ == "ping" then local bytes, err = _self.ws:send_pong() if not bytes then return ngx.exit(444) end elseif ... end
Hello! 2014-11-27 4:21 GMT-08:00 Nero.Ping: > 为了保证服务和浏览器的连接不断开,服务端需要定时往浏览器发送ping,我不太清楚这个最佳的发送ping的时机如何决策,不知道在每次读不到websocket > frame时就发送ping是不是最佳时机,或者是收到pong时再ping更好。 可以在 recv_frame() 返回超时错误时发送 ping. Regards, -agentzh