Advertisement

port selection

Started by April 23, 2002 05:47 AM
3 comments, last by haust 22 years, 9 months ago
hi, i would like to know how do choose the port value for your personal app ?? is there a free-for-all ports range ?? How do i know that a port, say 1234 or whatever, is already used ?? thanks.
Ports below (and including) 1024 are reserved, for protocols such as http, ftp telnet etc. you shouldn''t use these ports.
Other than those, you can bind to pretty much any port you want (below 65536). If you don''t set a port with sockets, it will automatically bind itself to a free port, if you try to bind to a port that is already in use, you will get an error. Generally, you can probably let clients use whichever port they can get, and just have the server with a set port.
Advertisement
On www.iana.org you can find a list of registered port numbers. But really, nothing''s going to stop you from using registered port numbers. It''s just that if you use one of the registered numbers, the server admin won''t be able to run your server if another server is run for the registered port.

You shouldn''t use < 1024 because only Administrator/root can bind to those ports, and a game server had better run non-root.

cu,
Prefect
Widelands - laid back, free software strategy
thanks for the info.
Ports larger than 49151 really shouldn''t be used either. If you look here you can see all the port assignments:
http://www.iana.org/assignments/port-numbers

I know one way to check if a port is in use... try binding to that port and see if you get a WSAEADDRINUSE error message. But I''m sure there must be a better way to tell if a given port is open, since thats what most firewalls do.

This topic is closed to new replies.

Advertisement