Solved

Opening & closing of ServerSocket

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse package explorer vs project explorer view 2 127
github account with ecipse 1 47
javap not working 8 44
JAVA API design with micro service cloud in mind 1 14
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…

776 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