szden
asked on
ServerSocketChannel.socket() is still bound after close()
Hi all,
I recoded my server program to use java.nio and it works fine.
When I try to close socket:
serverSocket.socket().clos e();
boolean b1 = serverSocket.socket().isBo und();
boolean b2 = serverSocket.socket().isCl osed();
and check values, b1 is true and b2 is true.
When I run netstat I see that state od port is "LISTENNING"
While I was using "old" IO, closing socket did excatly what I expected (netstat did not list port as Listenning).
How can I "unbind" socket without shuting down JVM?
Zdenko
I recoded my server program to use java.nio and it works fine.
When I try to close socket:
serverSocket.socket().clos
boolean b1 = serverSocket.socket().isBo
boolean b2 = serverSocket.socket().isCl
and check values, b1 is true and b2 is true.
When I run netstat I see that state od port is "LISTENNING"
While I was using "old" IO, closing socket did excatly what I expected (netstat did not list port as Listenning).
How can I "unbind" socket without shuting down JVM?
Zdenko
See how long that situation persists - you may find what you expect after a short time
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try closing the channel it self instead of its associated socket, like:
ServerSocketChannel serverSocket ...;
serverSocket.close();
I think that will help, because closing the socket only has to be done when using the old I/O-package. ServerSocketChannel's besides being closed also have to be decoupled from the Selector, which will not be done, when using the code:
serverSocket.socket().clos e();
ServerSocketChannel serverSocket ...;
serverSocket.close();
I think that will help, because closing the socket only has to be done when using the old I/O-package. ServerSocketChannel's besides being closed also have to be decoupled from the Selector, which will not be done, when using the code:
serverSocket.socket().clos