"java.net.BindException: Address already in use: connect" ? ?

C

cmk128

Hi
My java slcient connect to the server may many time by socket. My
problem is: "socket.close()" doesn't release the local port. After
running "new Socket()" many time, it will get "java.net.BindException:
Address already in use: connect" exception.
If i specify the local port to be use by "new
Socket("localhoist",18001,InetAddress.getLocalHost(),18002)", it get
the same error, because "socket.close()" doesn't release the port.
thanks
from Peter ([email protected])
 
I

Ingo R. Homann

Hi,

Hi
My java slcient connect to the server may many time by socket. My
problem is: "socket.close()" doesn't release the local port. After
running "new Socket()" many time, it will get "java.net.BindException:
Address already in use: connect" exception.
If i specify the local port to be use by "new
Socket("localhoist",18001,InetAddress.getLocalHost(),18002)", it get
the same error, because "socket.close()" doesn't release the port.
thanks
from Peter ([email protected])

Sounds to me like the *Socket* will be closed, but of course, the
*ServerSocket* will not be closed as well. The ServerSocket must be
closed explicitely.

Ciao,
Ingo
 
G

Gordon Beaton

My java slcient connect to the server may many time by socket. My
problem is: "socket.close()" doesn't release the local port. After
running "new Socket()" many time, it will get "java.net.BindException:
Address already in use: connect" exception.
If i specify the local port to be use by "new
Socket("localhoist",18001,InetAddress.getLocalHost(),18002)", it get
the same error, because "socket.close()" doesn't release the port.

It is normal for the address to remain in use for a few minutes after
closing the Socket.

It is however extremely unusual to care which port number is chosen by
the client. If you don't specify a client port number, the system will
simply choose an available one.

If you really do need to specify the client port number, you can also
use setReuseAddress() and the address will become available again
immediately after you close the Socket.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top