Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

java.net.SocketException: socket closed !!!! Please help

454 views
Skip to first unread message

eric.g...@evc.net

unread,
Dec 22, 1999, 3:00:00 AM12/22/99
to

Hi all,

I have trouble with start and stop a socket server, to start the server I
put the webServerOn on true and incocate the superclass start() method, it
run ok, but when I need to stop I use the stopWebServer() method and an
exception occured :

java.net.SocketException: socket closed
at java.net.PlainSocketImpl.socketAccept(Native Method)
Webserver stopped
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:406)
at java.net.ServerSocket.implAccept(ServerSocket.java:240)
at java.net.ServerSocket.accept(ServerSocket.java:224)
at WebServer.run(WebServer.java, Compiled Code)

and I can't restarted the serversocket

here is a simplification of the code

public class WebServer extends Thread
{
public void stopWebServer()
{
boolean webServerOn;
if(webServerOn)
{ webServerOn = false;
try
{serverSocket.close();}
catch( IOException ioe )
{;}
serverSocket = null;
}
}

public synchronized void run()
{
try
{serverSocket = new ServerSocket(port);
while (webServerOn)
{socket = serverSocket.accept();
socket.setSoTimeout( timeout );
socket.setTcpNoDelay(true);
System.out.println("From " +socket.getInetAddress().getHostAddress());
socket.close();
}
}
catch( Exception e )
{;}
}
}


Please help, me

Cheers,


eric.g...@evc.net

riceman

unread,
Dec 22, 1999, 3:00:00 AM12/22/99
to
What about calling

Thread.interrupt();

in stopWebServer()
This will stop ServerSocket.accept();
before ServerSocket.close();

just because
Even if you change the flag

webServerOn = false;

the thread runs and Socket acception is working...
and when You close the ServerSocket...
It throws SocketException...
so when you interrupt the acception before close the ServerSocket.
No Problem occurs...
(Actually InterruptedException thrown.)...

riceman

Don Vining

unread,
Dec 22, 1999, 3:00:00 AM12/22/99
to
I'm not sure why you consider this a problem. After all when you stop any
program, usually it's because you don't want it running anymore.

In java lots of times you'll see in the doc that once something has been closed
it cannot be reopened. This is probably true of sockets. However, this really
isn't a problem. After closing the ServerSocket, all you have to do is make a
new ServerSocket if you want to continue running.

Don
<eric.g...@evc.net> wrote in message news:83p8o9$idf$1...@jaydee.iway.fr...

0 new messages