Which Port to choose?

BlitzMax Forums/BlitzMax Programming/Which Port to choose?

beanage(Posted 2009) [#1]
Name tells it all. I need to determine a set of ports for my multiprocess engine, and i got absolutely no idea what criteria to select a port by.

Looking on other game engines, its just like they put on a randomizer.. "Hell yea, that number sounds great so lets take 27015!"

Help :/

BeAnAge


plash(Posted 2009) [#2]
Probably from the high-end range, and you should search on Google to see if any ports that you pick conflict with popular applications.


xlsior(Posted 2009) [#3]
Pretty much anything can be used, but to minimize collisions you probably should pick a high port. There are lists floating around with ports used by major applications, and it's probably advisable to pick one that isn't already taken by a mainstream program.
See here for a fairly substansive list: http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

Make sure that Also, if possible you may wish to give your program either the option to allow the user to manually specify a different port (in case they do have something that already uses your standard port), or have several automated 'fallback' ports to try in case the main one doesn't work.

when you do pick a number, you probably have less chance of problems if you pick an ugly number rather than a nice-looking one. the odds of some other program already using port 10000 or 22222 are probably larger than that it uses 21936 (for example)


Flemmonk(Posted 2009) [#4]
If its a connecting (outbound) port then you would use local port 0. If it is a listening port accepting (inbound) connections then it is best practise to use something >1024. Some ISPs still block ports below this value and so some users would have issues listening on them.


markcw(Posted 2009) [#5]
24178?


beanage(Posted 2009) [#6]
Thank you all for your answers. @xlsior, especially for that list, pretty helpful.

@flemmonk, why port 0 for outbound?


Winni(Posted 2009) [#7]
It's usually not the ISP that blocks ports below 1024, it's the underlying operating system: Linux, OS X and all real Unixes only allow applications with root privileges to use ports below 1024. Windows doesn't care about this.

There's an official list of 'well known ports' available:
http://www.iana.org/assignments/port-numbers

Unless you want to implement one of the protocols listed there, do not use any of those port numbers.

Other than that, you're right: Randomly pick a free port number and go. ;-)


beanage(Posted 2009) [#8]
@winni thanks for this second list seemed to be more complete. finally decided to take ports in range of 46k to 47k.. theres most unassigned ports there accrding to your list :). Thank you all.


Flemmonk(Posted 2009) [#9]
Well when you create a socket for outbound connection you dont usually specify the local port and so 0 is used which the operating system replaces with the next available port number.

You would not specify a local port to connect outbound from because that port might already be been used by another program.


beanage(Posted 2009) [#10]
aah, that clears things up :)