Solved

Opening & closing of ServerSocket

Posted on 1997-04-07
2
421 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
[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
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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

632 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