JavaFAQ Home » Networking
IP addresses are used to get packets to the right computer, but how do packets finds a program to which they are sent?
Usually every computer have several programs running at the same time and many of them communicate via Internet. Even more - all connections use the same physical Ethernet cable.
The packets are guided to the correct program according to its port number.
The port number is a 16 bit number and can be seen in an URL for example: https://www.javafaq.nu:80/
Because the port 80 is default when you use it, you will be redirected to http://www.javafaq.nu/
So, one application uses at least one port to communicate with another program via the same IP address. Actually think about IP address like about one big hotel and port number is a room in the hotel. Every guest leaves in its own room but to go to city and back home everybody uses the main door, at main entrance.
Many old programs use so named reserved port numbers, for example SSH uses port 22, telnet 23, FTP 21.
Also keep in mind that UNIX OSs reserve ports 1- 1023 for standard services - they are not accessible for programs you design . Windows has no such restriction, but if you design portable program it is wise to use ports above 1023. Actually much better to use ports from the end of the ports range, because many ports at the beginning are reserved (for well known port applications) and many are registered
Registered port means that some company officially registered that port to make sure that other programs are aware about it and will avoid to use it.
The Registered Ports are in the range 1024-49151. The port usage in this range can lead to problems with your software on some networks, where post which you have chosen are already used by some another program.
I always use ports in
Dynamic And/Or Private Posts Area, those from 49152 through 65535.
Port Numbers, the whole known list is here
Working Java code examples ( network oriented) you can find below:
Also some other Java code samples for the next four Java packages are below:
Printer Friendly Page
Send to a Friend
Search here again if you need more info!