local sock = assert(ngx.req.socket())
sock:settimeout(15000)
while true do
local line, err, part = sock:receive("*a")
if line then
ngx.log(ngx.ALERT, line)
ngx.say("log end!")
else
ngx.say("failed to receive a line: ", err, " [", part, "]")
break
end
ngx.sleep(1)
end
sock:close()
ngx.say("closed")
上面这段代码中,调用receive的时候会阻塞,然后客户端得到的是“failed to receive a line: timeout [abcdefg]”,其中“abcdefg”是我客户端发送的。那么问题就来了,它实际上是读的到的啊,为什么会阻塞直到timeout,为什么line为nil,为什么part是客户端发送的数据?求前辈们指导指导,谢谢哈。
各位朋友好,我最近开始用Openresty搭建一个tcp服务器,遇到这样的问题:local sock = assert(ngx.req.socket())
sock:settimeout(15000)
while true do
local line, err, part = sock:receive("*a")
'*a': reads from the socket until the connection is closed. No end-of-line translation is performed;if line then
ngx.log(ngx.ALERT, line)
ngx.say("log end!")
else
ngx.say("failed to receive a line: ", err, " [", part, "]")
break
end
ngx.sleep(1)
end
sock:close()
ngx.say("closed")
上面这段代码中,调用receive的时候会阻塞,然后客户端得到的是“failed to receive a line: timeout [abcdefg]”,其中“abcdefg”是我客户端发送的。那么问题就来了,它实际上是读的到的啊,为什么会阻塞直到timeout,为什么line为nil,为什么part是客户端发送的数据?求前辈们指导指导,谢谢哈。
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html