Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualSimonForsman

Posted 22 July 2012 - 11:06 AM

Almost all clients use random ports.




use ip address/port to identify clients. additionally you can assign a random session id to the user which he has to send with every packet

Good solution!
However, is that means if I want to allow a user to multi-login with the same IP, I can't fix the client port?
Is a MMORPG game client using random port normal?
Any pros and cons?
Thank you!


I can't think of a single gameclient that specifies the port it uses to recieve data, you should not use a random port though.
You should let the OS assign a free port(The port you get from the OS might seem random but there is usually a system to it) to your outgoing connections (there might be other applications using sockets on the users machine aswell and any attempt from your appilications side to force a specific portnumber might fail miserably).

Normally when you open an outgoing connection you only specify which port on the target machine you want to connect to and the OS assigns a port on which you can retrieve data using the same socket, if you open a second socket to retrieve data on a static port you will not only risk causing conflicts with other software, you will also break the functionality of most NAT routers.

With UDP you simply create your socket without specifying a port and use sento / recvfrom , (The server should specify a static port for its socket though)

#1SimonForsman

Posted 22 July 2012 - 11:02 AM

Almost all clients use random ports.




use ip address/port to identify clients. additionally you can assign a random session id to the user which he has to send with every packet

Good solution!
However, is that means if I want to allow a user to multi-login with the same IP, I can't fix the client port?
Is a MMORPG game client using random port normal?
Any pros and cons?
Thank you!


I can't think of a single gameclient that specifies the port it uses to recieve data, you should not use a random port though.
You should let the OS assign a free port to your outgoing connections (there might be other applications using sockets on the users machine aswell and any attempt from your appilications side to force a specific portnumber might fail miserably). (Normally when you open an outgoing connection you only specify which port on the target machine you want to connect to and the OS assigns a port on which you can retrieve data using the same socket, if you open a second listening socket to retrieve data on a static port you will not only risk causing conflicts with other software, you will also break the functionality of most NAT routers)

PARTNERS