Solved

Opening & closing of ServerSocket

Posted on 1997-04-07
2
418 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

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

Title # Comments Views Activity
Custom Java Application connects to database: Which one of the 20? 4 35
use lov values 2 64
how to debug htl and js pages 8 39
web project error add remove 1 32
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

830 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