Sign in to follow this  
VBStrider

TCP Client Port Forwarding

Recommended Posts

VBStrider    303
While behind a router, some form of port forwarding is required for any inbound packet to get to it's destination. My question is why do TCP clients seem to "magically" forward themselves? Does the router simply automatically forward any outbound TCP connections (and only outbound TCP connections)? VBStrider [Edited by - VBStrider on July 12, 2007 10:29:16 AM]

Share this post


Link to post
Share on other sites
taby    1265
You are correct in essence. A lot of firewalls only block incoming traffic. When an outbound packet is sent, the firewall registers this as being a change in the state of what types of packets need to be allowed back, and which internal IP address it needs to send those packets to.

This is not specific to TCP packets, as it should also apply to UDP and ICMP packets in most default configurations.

Share this post


Link to post
Share on other sites
VBStrider    303
Why does StarCraft require it's UDP port to be forwarded then?

By the way, I just noticed that something like this was asked not too long ago: http://www.gamedev.net/community/forums/topic.asp?topic_id=451659 so sorry if this is spam.

VBStrider

Share this post


Link to post
Share on other sites
Evil Steve    2017
To expand a little on what taby said:
When a TCP client starts up, the first thing it does it send a packet to the server (A TCP SYN packet I belive). The router sees this packet going from the client to the remote machine, and so it notes own in an internal table it has the source and destination IP addresses and ports.

Next, the server replies (with a TCP ACK packet I belive) to the IP address and port it came from. The router recieves this packet, and looks at the IP and port it came from. It sees that it's coming from a IP:port that was used by the client machine earlier, and so it auto-forwards the packet to the IP:port of the client.

Client machine recieves packet and does whatever it wants with it.

The same is possible with UDP as well, it's not just limited to TCP.

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by VBStrider
Why does StarCraft require it's UDP port to be forwarded then?
I'd assume that it's only needed if you're hosting a server on your machine. Because then the first packet sent would be TO the machine behind the router, not FROM it.

This is also needed if you're playing peer-to-peer, because it's entirely possible that both players will be behind a router, so one of them (the server / host) will have to have the port forwarded correctly.

I've never played Starcraft, so I've no idea if this is correct with respect to peer-to-peer and whatnot.

Some commercial games can get around you having to forward the port by either hosting the server themselfs (So they do the port forwarding), or by using NAT punchthrough (Google for this - although it's only really applicable to UDP).

Share this post


Link to post
Share on other sites
VBStrider    303
How are you able to connect to the same game from the same LAN on two different computers then? Does windows just work with the router to make sure that it chooses a client port that is not used on any other computer on the network?

Also, I am unable to player StarCraft through Battle.net with a friend on my LAN because only one of us actually gets to play. The other gets severe "lag", can't play really and can't read chat messages... But can connect.

VBStrider

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by VBStrider
How are you able to connect to the same game from the same LAN on two different computers then? Does windows just work with the router to make sure that it chooses a client port that is not used on any other computer on the network?
The router sees that both clients are on the same side of it, and lets them connect directly. When you connect to a remote machine, Windows choses the port (Usually, unless the app tells it not to). On a LAN with two PCs, one will be the server, and will be listening for connections on the game port (Say, port 1234), and the other PC will choose a random port (say 60000) to connect to the first PC. The hosting PC then creates a new connection on a random port (Which doesn't have to be different from the connecting PC, but usually is), and you have a connection between the two PCs.
Even if both PCs manage to choose the same random port, it'll still work, because the IP:port pair is still unique.

Quote:
Original post by VBStrider
Also, I am unable to player StarCraft through Battle.net with a friend on my LAN because only one of us actually gets to play. The other gets severe "lag", can't play really and can't read chat messages... But can connect.
Sounds like a problem with the game more than anything else to be honest.

Share this post


Link to post
Share on other sites
VBStrider    303
Quote:
The router sees that both clients are on the same side of it, and lets them connect directly.

That's not what I meant... I mean if two people are playing the same game on the same LAN. So for instance, lets say a group of people want to play World of Warcraft together over a single LAN. They are not connected to each other, they are connected to a remote server.

After reading http://www.mindcontrol.org/~hplus/nat-punch.html it appears as though the router uses one of it's own ports, so that solves that problem.

Thanks for the information, I've always wondered how the router handles that. And by the way, if someone does happen to know what is wrong with StarCraft, I would greatly appreciate it if you informed me via a PM or a reply.

VBStrider

Share this post


Link to post
Share on other sites
snisarenko    526
Quote:
Original post by VBStrider

That's not what I meant... I mean if two people are playing the same game on the same LAN. So for instance, lets say a group of people want to play World of Warcraft together over a single LAN. They are not connected to each other, they are connected to a remote server.

After reading http://www.mindcontrol.org/~hplus/nat-punch.html it appears as though the router uses one of it's own ports, so that solves that problem.

VBStrider


The two computers on the LAN may choose the same outgoing port, but the NAT creates two different external ports. So even though the IP for both connections is the same (Router's IP) the external ports are different, because NAT chooses the external ports for you. So the server still sees a unique IP:port for each connection.

Share this post


Link to post
Share on other sites
Nypyren    12065
StarCraft's code has a bug that kills performance when two computers are behind the same router but involve players on the other side of the router. I don't know the details, but it's definitely something unique to StarCraft.

It's possible that the StarCraft server is keeping track of clients by IP rather than by endpoint (IP+Port) and assumes that it's sending enough updates to a given IP in a given timespan or something.

Share this post


Link to post
Share on other sites
VBStrider    303
If you have two computers (or more) connected to the network and the port is forwarded to computer A but you try to play StarCraft on computer B, the same exact thing happens... I don't think update frequency is the problem in that case.

Edit:
I found this in the blizzard support section: http://www.blizzard.com/support/?id=asc0692p
It appears as though you need a unique IP address for each computer.

VBStrider

[Edited by - VBStrider on July 14, 2007 5:25:17 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this