Solved

Opening & closing of ServerSocket

Posted on 1997-04-07
2
407 Views
Last Modified: 2006-11-17
I have a program like:

//*********
.....
ServerSocket s1;

s1=new ServerSocket(21);
....
 //invoke a thread to accept multiple connections
new somethread(s1, ..).start();
....
....

public boolean action(Event e, Object arg)
{
if(somethingIsTrue)
 {
  try   {
         System.out.println("going to close ServerSocket");        
         s1.close();      // the program hangs here
         System.out.println("ServerSocket closed");        
       
        }
        catch(Exception e) {     System.out.println("ServerSocket
excpt");   }
 }
.......
}
...
//*******************


I face two problems while running this problem:

1. I am not able to close ServerSocket. It doesn't even throw any
exceptions. The program simply hangs there. Of course, I am able to
close the ServerSocket s1, if I accept connections without invoking
a thread like the one shown above, i.e

 //invoke a thread to accept multiple connections
new somethread(s1, ..).start();

In Java, it appears you cannot shutdown a server and restart it
without quitting the entire program.

2. If a daemon is already on the port 21, any attempt to open
ServerSocket
on the same port should throw some exceptions but nothing happens in
Java.

I use JDK1.0.2 under win95 but if it is fixed in JDK1.1 can I simply
replace java.net package in CLASSES.ZIP in JDK1.0.2 with the java.net
package
in JDK1.1.

Has anyone come across this problem?

Thanks
Parameshwar Babu


--
0
Comment
Question by:pbabu
2 Comments
 
LVL 1

Expert Comment

by:trof
ID: 1219475
Tell us more about your VM implementation. Is it pure java.exe or JView (j++) or what ?
0
 

Accepted Solution

by:
tlandry earned 200 total points
ID: 1219476
Phabu,

Failure of server sockets to close is a known bug in JDK1.02,
at least for Win95/NT.  Simply using the JDK1.1 class files
may not be enought to fix the situation.  You may need
to use the JDK1.1 VM as well, provided Javasoft fixed this
bug in 1.1.

Hope this helps,

Ted
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

746 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

12 Experts available now in Live!

Get 1:1 Help Now