Solved

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

Posted on 2004-08-26
5
1,140 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

752 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