Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1242
  • Last Modified:

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().close();
  boolean b1 = serverSocket.socket().isBound();
  boolean b2 = serverSocket.socket().isClosed();
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
0
szden
Asked:
szden
1 Solution
 
CEHJCommented:
See how long that situation persists - you may find what you expect after a short time
0
 
TimYatesCommented:
I had a quick look at the source for serversocket, and I don't think you can...
0
 
dsj_shockCommented:
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().close();
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now