A simple networking question

Started by
3 comments, last by rip-off 11 years, 6 months ago
I've just started learning winsockets.

When my client computer attempts to connect to a server, I'm assuming it has picked a port to tell the server it can use to communicate back. Is this a standard port or a random one?

Thanks!
Advertisement
Servers need to have a fixed inbound port for the listening system. This is specified in your program.

Generally apps that connect to the server don't care about the outbound port and let the system use any random unused port.
That would make sense. I'm assuming the router associates this random port with the internal IP address of the computer that sent the request.

That would make sense. I'm assuming the router associates this random port with the internal IP address of the computer that sent the request.


Yes, that's standard router procedures.

(LAN IP / internet IP)
192.168.1.2:61455 <-> 3.43.125.18:12233.

You'll need port forwarding to host a game on a specific router port.

Everything is better with Metal.

Just to be clear - there are two steps here. The client will generally generate a random port when opening the connection (usually by delegating to the operating system, not by using rand()), and the typical NAT router may further randomise this again on the way to the internet. Thus server will see the router's address and the router's chosen port, while the client will believe it is using a different port.

This topic is closed to new replies.

Advertisement