Page 1 of 1

Question about setsockname and portforwarding inside local network

Posted: Sun Apr 12, 2020 6:49 pm
by Akexandre
Hello there :crazy:

I'm posting my question here because I'm trying to find the solution by searching on internet and multiple network forum but I do not understand (maybe it's obvious).
I have a code with server and client and on local machine and it works. Trouble is when I try to have the server on my laptop one (192.168.0.10) and client on my second laptop (192.168.0.11).

Code on server :

Code: Select all

local socket = require('socket')
udp = socket.udp()
udp:setsockname('*', 6731)
udp:settimeout(0)
Code on client :

Code: Select all

local socket = require "socket"
local address, port = "localhost", 6731
udp = socket.udp()
udp:setpeername(address, port)
udp:settimeout(0)
Here localhost refer to ::1 - I try to change both side with 127.0.0.1 it works (logic). When i try to put on server "127.0.0.1" and on client "192.168.0.10" it's not working.

I know that I need to use port forwarding on my router (e.g. apache works well on port 4513) and I added the rule but nothing happens. I assume the issue is before : when on my server side I try to see if 6731 is listening with netstat, I do not see anything (even with firewall fully turned off).

I have to admit, I'm lost and my question is more about network than lua but I'm maybe not the only one and maybe I'm missing something with UDP protocol.

I hope I will have a chance to understand this, I would like to enjoy my game with friends and for now I'm stucK.

Thank you in advance for your precious help, I'm looking forward to have news from you

Cheers :awesome:

Alex

Re: Question about setsockname and portforwarding inside local network

Posted: Sun Apr 12, 2020 8:28 pm
by ReFreezed
Port forwarding does nothing within a local network - it's only for connections from the outside, so that's not the problem. I think setpeername() should take the address you want to connect to and setsockname() should take "*". (My socket knowledge is a little bit rusty.)