所以,我正在编写一个lua mod来绑定Isaac。我制作了一个lua客户机(使用luasocket)和一个python服务器。在
在本地,一切正常,但是当我使用我的公共ip(我在路由器上进行端口转发)测试时,lua客户端在第二次接收时超时。
我不知道是什么原因造成的,日志上写着“CID超时”。在
编辑(忘记添加此项):
奇怪的是,对于python服务器,好像他已经发送了它,因为当我在服务器上添加超时时,只有接收到消息“[RCID]\n”超时。在
以下是lua mod的网络部分:
在local socket = require("socket")
local connectIP = ""
local currentPort = 21666
local loopTimeout = 10
function Network.SendData(data)
if currentBehaviour == Behaviour.CLIENT then
client:send(data.."\n")
end
end
function Network.StartClient()
if currentBehaviour == Behaviour.IDLE then
client = assert(socket.tcp())
client:connect(connectIP,currentPort)
currentBehaviour = Behaviour.CLIENT
client:settimeout(loopTimeout)
local seed,errs = client:receive()
if errs~="timeout" and errs~=nil then
Network.CloseConnection();
Isaac.DebugString("seederror:"..errs);
elseif errs=="timeout" then
Network.CloseConnection();
Isaac.DebugString("timeout at seed");
elseif errs==nil then
Isaac.DebugString("Seed: : "..seed);
Isaac.ExecuteCommand("seed "..seed)
end
local CID,err = client:receive()
if err~="timeout" and err~=nil then
Network.CloseConnection();
Isaac.DebugString("ciderror:"..err);
elseif err=="timeout" then
Network.CloseConnection();
Isaac.DebugString("timeout at CID");
elseif err==nil then
Isaac.DebugString("CID : "..CID);
ClientID = tonumber(CID)
Network.SendData("[RCID]")
end
end
end
这是服务器:
在
^{pr2}$