简体   繁体   中英

C#-Lua UDP incompatibility (no message received)

My problem: A UDP message sent by a C# application (.NET 4.6.1) is not showing up in a Lua client (LOVE 0.9.2 with bundled LuaSocket).
The send code is hilariously simple:

UdpClient listener = new UdpClient(port);
listener.Send(bytes, bytes.Length, "client_ip", 1234);

The receive code is relatively simple as well:

local socket = require("socket")
local address,port = "server_ip",1234
local udp = socket.udp()
udp:settimeout(0)
udp:setpeername(address,port)
local data,msg_ip,port_nil

function love.update(dt)
    repeat
        data,msg_ip,port_nil = udp:receive()
        if data then
            print(data)
        elseif msg_ip~="timeout" then
            print(msg_ip)
        end
    until not data
end

As Michael said, the problem was not, in fact, an incompatibility in the UDP implementations. I forgot to include udp:setsockname('*',port) in my client Lua code, which is a completely different and much easier problem. Unless there are complaints, I will leave the mistitled question up in the hopes of helping out any other misguided souls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM