Solved

ServerSocketChannel.socket() is still bound after close()

Posted on 2004-08-26
5
1,108 Views
Last Modified: 2012-08-13
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
Comment
Question by:szden
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11901637
See how long that situation persists - you may find what you expect after a short time
0
 
LVL 35

Accepted Solution

by:
TimYates earned 125 total points
ID: 11901639
I had a quick look at the source for serversocket, and I don't think you can...
0
 

Expert Comment

by:dsj_shock
ID: 11901842
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question