luasocket接收的数据中必须要以”\n”做结束符才能收到数据

luasocket接收的数据中必须要以”\n”做结束符才能收到数据

网上查询,有人说不需要,

http://forum.cocos.com/t/luasocket/17733

有人说需要

https://groups.google.com/forum/#!topic/openresty/tiyqZG59sGY

经测试,scoket client发送数据的时候,必须要加结束符才能接收到数据。

local socket = require("socket")
host = host or "localhost"
port = port or 8080
if arg then
	host = arg[1] or host
	port = arg[2] or port
end
print("Attempting connection to host '" ..host.. "' and port " ..port.. "...")
c = assert(socket.connect(host, port))
print("Connected! Please type stuff (empty line to stop):")
l = io.read()
while l and l ~= "" and not e do
	assert(c:send(l .. "\n"))   --这个结束符必须要加
	l = io.read()
end

发表评论

电子邮件地址不会被公开。 必填项已用*标注