my udp code doesn't work when sending from computer 1 to computer 2, but it works sending from comp 2 to comp 1. I have tried both on the same computer, works fine as expected. The computers are connected through ethernet on a lan, and windows picks up the computers and lets me log in and read/write to/from the computers. Server:
local socket = require "socket"
-- begin
local udp = socket.udp()
udp:settimeout(1)
udp:setsockname('*', 12345)
local data, msg_or_ip, port_or_nil
local cmd, parms
local running = true
print "Beginning server loop."
while running do
data, msg_or_ip, port_or_nil = udp:receivefrom()
if data then
print(data,msg_or_ip,port_or_nil)
udp:sendto(data,msg_or_ip,port_or_nil)
elseif msg_or_ip ~= 'timeout' then
print("Unknown network error: "..tostring(msg))
end
socket.sleep(0.01)
end
Client:
local socket = require "socket"
local address, port = "192.168.137.161", 12345
udp = socket.udp()
udp:settimeout(1)
while true do
udp:setpeername(address, port)
udp:send(io.read())
udp:close()
--udp:setsockname("*",12345)
data, msg_or_ip, port_or_nil = udp:receivefrom()
print(data, msg_or_ip, port_or_nil)
udp:close()
end
The client sends the message, server picks it up, and should echo it right back, but the client spits out
nil refused nil
, with the tab between nil and refused.
I think this is mostly just something with sending from the server computer to the client computer, since it should just echo the data.
I could see how this problem would be hard to answer, due to not everyone having full access to two computers at once. For the record lua 5.1 is used on both, socket is v2.0.2 on both as well.
for all who were wondering, it was because I closed the socket. nothing major.