[435] in java-interest

home help back first fref pref prev next nref lref last post

Re: NetworkServer

daemon@ATHENA.MIT.EDU (Jonathan Payne)
Wed Jun 21 17:39:26 1995

Date: Wed, 21 Jun 1995 14:18:48 -0700
From: jpayne@starwave.com (Jonathan Payne)
To: gzoller@imonics.com
Cc: java-interest@java.sun.com
In-Reply-To: <9506212030.AA07035@antioch.imonics.com> (message from Gregory Zoller - Imonics Development on Wed, 21 Jun 1995 16:30:15 -0400)

> From: Gregory Zoller - Imonics Development <gzoller@imonics.com>
> Date: Wed, 21 Jun 1995 16:30:15 -0400
> X-Sun-Charset: US-ASCII
> Sender: owner-java-interest@java.sun.com
> Precedence: bulk
> X-Info: To unsubscribe, send 'unsubscribe' to java-interest-request@java.sun.com
> Content-Type: text
> Content-Length: 1726
> 
> 
> Hi All...
> 
> I'm trying to find a reliable way to stop a NetworkServer instance.
> It'd be very nice if this class had a stop() method that would 
> terminate NetworkServer's run() method and free the port. :-)

Wow, that sure sucks that there's no way to close a server.

> My Applet launches and starts a NetworkServer object.  The problem
> occurs if someone reloads the page.  The previous instance's Thread
> is still running, hogging the port.
> 
> I've tried subclassing NetworkServer, and adding a stop() method:
> 
>         public synchronized void stop() {
>                 Thread.currentThread().stop();
>         }

All you did in this instance was kill the current thread, the one you
were using to execute the call to stop(!), not the thread that was
running the server.

> That didn't work.
> 
> Then I tried adding the following to Java's NetworkServer class:
> 
>     private boolean stopRequest = false;
> 
>     final public void stop() {
>         stopRequest = true;
>     }
> 
>     // inside run() changed while( true ) to this...
>     while ( !stopRequest ) {
> 
> This all compiled fine.  When I ran it and called NetworkServer's
> new stop() method, I got this message:
>
> java.lang.IncompatibleClassChangeException net.NetworkServer: method stop()V not found
>         at AppServer.destroy(AppServer.java:141)
>         at browser.AppletDisplayItem.destroy(AppletDisplayItem.java:318)
>         at browser.Document.destroyApplets(Document.java:305)
>         at browser.WRWindow.destroyApplets(WRWindow.java:223)
>         at browser.WRWindow.uncacheCurrentDocument(WRWindow.java:513)
>         at browser.WRWindow.reload(WRWindow.java:405)
>         at browser.ReloadButton.selected(hotjava.java:512)
>         at awt.WServer.run(WServer.java:66)
> Failed to stop: java.lang.IncompatibleClassChangeException: net.NetworkServer: method stop()V not found

This means that you compiled your new NetworkServer and your applet
that used that new NetworkServer in one context, but your browser is
running in a context which has the old version of NetworkServer.  That
is, the compiler happily compiled a reference to the stop() method in
NetworkServer because the compile saw one in NetworkServer when it was
compiling.  But HotJava is still running with the old version.  Maybe
you (1) never stopped hotjava and just reloaded your applet, or (2)
forgot to put the new NetworkServer your classpath for executing
HotJava.

In any case, it seems clear that the way things are set up now, you
have to change NetworkServer.  That is, you can't subclass it and do
something smart, because the necessary instance variables are private.
This means that nobody else using your applet will be able to run your
stuff the way you do.

With that in mind, I think the best thing to do would be to either
make serverInstance accessible (via a method perhaps), or add a method
to NetworkServer called stop() which closes the socket, sets that
variable to true, and then make sure that the the exception class in
the main loop of the server doesn't try to restart the server in that
case.

> Any ideas?
> 
> GregZ
> -
> Note to Sun employees: this is an EXTERNAL mailing list!
> Info: send 'help' to java-interest-request@java.sun.com
> 
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post