How does the UDP Server know the difference between two players behind a router?

Started by
8 comments, last by RenderTarget 17 years, 10 months ago
How does the UDP Server know the difference between six players behind a router? Sorry for these questions. I looked all over the forums and could not find a specific answer. Lets say I have a UDP Server at IP: 69.3.1.32 Port 8301 Then at my friends house he has 6 computers setup behind his router, but he only has 1 IP which is 64.3.4.21 .... I run my client app on each of his 6 computers. These client apps each send 1 udp packet to the server at 69.3.1.32 Port 8301 Will the UDP server app receive them like this. 1 - incoming UDP packet from: 54.3.4.2:8301 2 - incoming UDP packet from: 54.3.4.2:8301 3 - incoming UDP packet from: 54.3.4.2:8301 4 - incoming UDP packet from: 54.3.4.2:8301 5 - incoming UDP packet from: 54.3.4.2:8301 6 - incoming UDP packet from: 54.3.4.2:8301 Thus I won't know which UDP packet came from which computer, unless I include a username or unique ID in the UDP packet? Please help. If this is a redundant question i'm very sorry! Luzarius
Advertisement
Im not positive on my answer but this may be right. I have a router and 4 computer hooked up to it. Each computer is assigned a different router ip address. 192.168.1.100,192.168.1.101,ect. So each computer is actually acting as its own ip.
West Side...
The router assigns a different port on the external interface for each IP/port combination sending TO the internal interface.

So your server is at 69.3.1.32:8301 (this may be a router's external IP with port forwarding set up - DON'T USE A DMZ IF YOU DON'T HAVE TO)

The router at your friends house:
External (WAN) 134.163.1.45 (no port open till a client punches through).
Internal (LAN) 192.168.0.1 (this is the gateway for his network).

Your friend's PCs:
192.168.0.10
192.168.0.5
192.168.0.3

192.168.0.10 creates a socket, port 3432 (system assigned) UDPs to 69.3.1.32:8301.
The IP address is not on the local network, so the router forwards it on - NOT NECESSARILY FROM THE SAME PORT - your server recieves from 134.163.1.45:1335 for example. The router holds that port (1335) open so replies can be accepted and forwarded to 192:168.0.10:3432.

Now 192.168.0.5 connects, from it's system-generated port of say, 3352. Again, the router forwards the send and assigns another port (say 1336). The router's NAT table now looks like:

192.168.0.10:3432 <-> 134.163.1.45:1335
192.168.0.5:3352 <-> 134.163.1.45:1336 (same IP, different port)

So in short, you'll notice different port numbers from connecting clients.
Winterdyne Solutions Ltd is recruiting - this thread for details!
Quote:
So in short, you'll notice different port numbers from connecting clients.


Do you know if these ports will ever change? I was thinking of using the IP & port to identify a user. But it may look as though I have to place an ID in the UDP packet which I was trying to avoid. A unique id for each user.

The port number will not change during the lifetime of the connection. Other than that, you can make no other real guarantees about the port numbers.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

From previous answers here, it sounds as though one client should keep the same IP/port combination during a session. Some (older) routers can be bad though and switch them.
Yes - *generally* the port number won't change.

You can basically rely on the port to stay the same - it only gets changed if the router is idle (no thru transmission) for so long that it assumes the connection should be dead - the NAT entry is removed, and as soon as a new outgoing packet hits the router a new NAT entry (and external port) is created.


Winterdyne Solutions Ltd is recruiting - this thread for details!
Quote:Original post by _winterdyne_
Yes - *generally* the port number won't change.

You can basically rely on the port to stay the same - it only gets changed if the router is idle (no thru transmission) for so long that it assumes the connection should be dead - the NAT entry is removed, and as soon as a new outgoing packet hits the router a new NAT entry (and external port) is created.


Aye, this is why keep alive packets should be sent to ensure that you don't idle timeout, although they are only needed during idle periods. As far as the game is concerned that would probably appear to be an entirely new customer, and as such it would react accordingly (either ignoring them, or sending back an error message).

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Quote:Original post by luzarius
Will the UDP server app receive them like this.

1 - incoming UDP packet from: 54.3.4.2:8301
2 - incoming UDP packet from: 54.3.4.2:8301
3 - incoming UDP packet from: 54.3.4.2:8301
4 - incoming UDP packet from: 54.3.4.2:8301
5 - incoming UDP packet from: 54.3.4.2:8301
6 - incoming UDP packet from: 54.3.4.2:8301

Thus I won't know which UDP packet came from which computer, unless I include a username or unique ID in the UDP packet? Please help. If this is a redundant question i'm very sorry!

Luzarius


Okay, so from what I understand there are six computers and each send out a packet over UDP. So shouldn't each packet receive a different demux? Meaning, each computer should have its own discernable IP host address (unless it's some subnetting issue, which I have no idea about...). So this problem should never happen.

What I would be more concerned about is if a packet is received out of order. I don't think UDP keeps sequence numbers, so if you receive a packet out of order you just have to deal with it.

Someone please correct me if I'm wrong... :|
The OP was asking about subnetting and NAT. Nothing to do with packet order.
[sub]My spoon is too big.[/sub]

This topic is closed to new replies.

Advertisement