Solved

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

Posted on 2004-08-26
5
1,044 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

705 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now