Lua客户端,Python服务器,本地一切正常,网络超时

Lua客户端,Python服务器,本地一切正常,网络超时,python,networking,lua,luasocket,Python,Networking,Lua,Luasocket,所以,我正在为Isaac的绑定编写一个lua mod。我使用luasocket和python服务器创建了一个lua客户机 在本地,一切正常,但当我使用我的公共ip测试它时,我在路由器上进行端口转发,lua客户端在第二次接收时超时。 我不知道是什么原因,日志显示CID超时 编辑并添加以下内容: 奇怪的是,对于python服务器来说,就好像他已经发送了它一样,因为当我在服务器上添加超时时,只有消息[RCID]\n的接收超时 以下是lua mod的网络部分: 这是服务器: 所以,最后,没有问题,问

所以,我正在为Isaac的绑定编写一个lua mod。我使用luasocket和python服务器创建了一个lua客户机

在本地,一切正常,但当我使用我的公共ip测试它时,我在路由器上进行端口转发,lua客户端在第二次接收时超时。 我不知道是什么原因,日志显示CID超时

编辑并添加以下内容: 奇怪的是,对于python服务器来说,就好像他已经发送了它一样,因为当我在服务器上添加超时时,只有消息[RCID]\n的接收超时

以下是lua mod的网络部分:

这是服务器:


所以,最后,没有问题,问题是:我的路由器不支持发夹,当试图使用本地网络的公共ip时,会产生奇怪的错误。它与网络外的PC机配合良好

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
import socket
import select
from parse import *



IsaacClients = {}

seed = b"98BN MJ4D\n"

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('', 21666))
server.listen(10)

num_clients = 0

server_launched = True
connected_clients = []
while server_launched:

    connections_asked, wlist, xlist = select.select([server],
        [], [], 0.05)

    for connection in connections_asked:
        connection_client, info_client = connection.accept()
        print(info_client)

        connected_clients.append(connection_client)
        print("Sending Seed")
        connection_client.sendall(seed) # send the seed
        print("Seed Sent")

        num_clients = num_clients +1
        check = ""
        counter = 0
        while check != "[RCID]\n" and counter<100: # try 100 times to send the ClientID
            print("Sending ClientID")
            try:
                connection_client.settimeout(0.1)
                connection_client.sendall((str(num_clients)+"\n").encode())
                check = connection_client.recv(7).decode() # try to check if it has received it
                connection_client.settimeout(None)
            except:
                pass
            counter=counter+1
            if counter == 100:
                server_launched = False
        print("ClientID Sent")



    clients_to_read = []
    try:
        clients_to_read, wlist, xlist = select.select(connected_clients,
                [], [], 0.05)
    except select.error:
        pass
    else:
        for client in clients_to_read:
            msg_recved = client.recv(1024)
            msg_recved = msg_recved.decode()
            print("[] {}".format(msg_recved))
            if msg_recved.find("[END]")!= -1 :
                server_launched = False
            msg_recved = msg_recved.split('\n') # split into lines

            for line in msg_recved:
                data = parse("[ID]{ID}[POS]{x};{y}[ROOM]{RoomIndex}[CHAR]{CharacterName}[REDM]{MaxHeart}[RED]{Hearts}[SOUL]{SoulHearts}", line)
                if data != None :
                    IsaacClients[data['ID']] = data
            luaTable = "{" # start the generation of the lua table that will be sent
            for player in IsaacClients.values():
                luaTable = luaTable + "[" + player['ID'] +"]={ID=" + player['ID'] + ",POS={x=" +player['x']+ ",y=" +player['y']+ "},ROOM=" +player['RoomIndex']+ ",CHAR='" +player['CharacterName']+ "',REDM=" +player['MaxHeart']+ ",RED=" +player['Hearts']+ ",SOUL=" +player['SoulHearts']+ "}"
            luaTable = luaTable + "}\n"
            print(luaTable)
            print("Sending Table")
            client.sendall(luaTable.encode())
            print("Table Sent")
print("Server closing")
for client in connected_clients:
    client.close()