Local TCP port check not open in Java

Is there an easy way to make sure that the local port is not open yet. Some TCP socket servers (such as Grizzly) do not seem to perform this check by default. When this check is missing, the server starts to start and respond, but the client code simply connects to the old server, which was not turned off. It can be very bad!

Is there a simple line of Java code that can verify that a port is not yet in use by another process?

0
source share
1 answer

I see two obvious ways to do this:

  • try connecting to this port on the local host, if you accept it, the port is in use
  • ServerSocket . " ",

, .

+3

Source: https://habr.com/ru/post/1750369/


All Articles