NAT typically works by using port translation. This basically means
that only if host A on port X, who is behind a NAT box, sends a UDP
datagram to host B on port Y, who is not behind a NAT or has a NAT/
firewall with proper port-forwarding, host B can send a datagram to
host A. However, host B has to send the datagram a new address, C
(the address of the NAT), and a new port number, Z, where Z is a
random port number picked by the NAT box. When the NAT box receives
the packet addressed to (C,Z), it will translate the packet’s
destination address and forward it on to host A on port X.
Diagrammatically, we have
A — (A:X,B:Y,data1) --> NAT — (C:Z,B:Y,data1) --> B
A <-- (B:Y,A:X,data2) — NAT <-- (B:Y,C:Z,data2) — B
where (source address:port, destination address:port, data payload)
is our (structurally simplified) UDP packet.
This only works because the host behind the NAT sends the first
packet, because NAT maintains a translation table to map C:Z to A:X,
but this mapping only gets made when there is outbound traffic first.
So what you have to do is have the server (B) has to examine the
packet and determine what C and Z are (what the client’s address and
port number are), rather than send the data to a fixed port number.
Im pretty sure that the client code can basically stay the same though.
Also, if youre trying to figure out how a particular game’s network
protocol works, i highly recommend using ethereal, which lets you
look at individual IP packets.
hope this helps
spencerOn Apr 11, 2006, at 7:00 PM, norco at ten-arc.net wrote:
There is this game I am modaling my game after, but I have no clue
does it… but the game client (players) can log into the server and
server is able to send UDP packets to the client. The client creates a
random UDP port. the clients can be behind a router or firewall but it
still get the UDP packets. BUT To host a game server from behind a
you first have to portforward TCP and UDP ports for players to
yet you have to do none of this if connecting to a server
for TCP since thats outbound).
Again, the players need no configuration to receive UDP packets
I have no clue how this is done because if you host a server you must
porforward or unblock a specific port in the firewall. I’m trying
this with SDL_Net. It is critical players receive UDP packets without
router configuration. But am unable to figure this out. Any ideas?
SDL mailing list
SDL at libsdl.org