Jump to content

  • Log In with Google      Sign In   
  • Create Account

A simple networking question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 GameCodingNinja   Members   -  Reputation: 167

Like
0Likes
Like

Posted 15 October 2012 - 09:40 AM

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!

Sponsor:

#2 frob   Moderators   -  Reputation: 21311

Like
0Likes
Like

Posted 15 October 2012 - 10:47 AM

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.
Check out my personal indie blog at bryanwagstaff.com.

#3 GameCodingNinja   Members   -  Reputation: 167

Like
0Likes
Like

Posted 15 October 2012 - 12:02 PM

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.

#4 0BZEN   Crossbones+   -  Reputation: 2016

Like
0Likes
Like

Posted 16 October 2012 - 11:47 AM

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, 16 October 2012 - 11:47 AM.

Everything is better with Metal.


#5 rip-off   Moderators   -  Reputation: 8222

Like
0Likes
Like

Posted 16 October 2012 - 01:58 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS