• Advertisement
Sign in to follow this  

A simple networking question

This topic is 1923 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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. Edited by papalazaru

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement