There are a number of ports that are assigned to common services. For instance SMTP servers use port 25, HTTP use port 80. There is a list of well-known ports that has a list of services and the ports that they use. This information (and almost everything regarding TCP/IP) is contained in a document called an RFC.
This page has a list of all well-known ports:
http://www.codecutters.org/resources/knownports.html
It also links to a lot of other good stuff. As a general guideline, your application should never use any port numbers between 0 and 1023 unless you are actually providing one of the services listed on that page. There are also a lot of "registered" ports in use, see this page for more info:
http://www.codecutters.org/resources/regports.html
So what port should you use? Well, that's hard to say. You can pretty much choose a port at random above 1023. However, it is advisable to stay away from any of the registered ports. There are a lot of them, but there are also a lot that have not been claimed. I recommend something in the 40000s simply because not many people use that range. The range from 49152 to 65000 is also defined as "private" so you may wish to use a port from that range.
Ideally, you want to be able to specify the port you use on both the server and the client. Making this something you can configure instead of hard-coding it will go a long way towards preventing conflicts.
One last thing you can do to determine what ports are in use on a network is to use a tool like Nmap to do a port scan. Nmap is available for download from http://www.insecure.org/nmap/ Nmap is a tool that is usually used for checking network security but can be useful for other things like finding out what ports are in use on a network.
Martin Fredrickson
Test Engineer
Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128