0 votes
1 view
in Java by (10.2k points)

I want to start a server which listen to a port. I can specify port explicitly and it works. But I would like to find a port in an automatic way. In this respect I have two questions.

  1. In which range of port numbers should I search for? (I used ports 12345, 12346, and 12347 and it was fine).

  2. How can I find out if a given port is not occupied by another software?

1 Answer

0 votes
by (46.1k points)
If you pass 0 as the port number to the constructor of ServerSocket, It will allocate a port for you.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...