I have built a client server application using javax websockets.Though JSR 356 doesn't have methods to stop websocket container, i managed to stop the container after casting to jetty Lifecyle.Once stopping the container i have wrote
system.exit(1);
But the return is code always zero from the client program.
code: @ClientEndpoint
public boolean close()
{
try
{
if(this.container != null && this.container instanceof LifeCycle) {
logger.trace("stoping container...");
((LifeCycle) this.container).stop();
}
this.session.close();
return true;
}
catch (Exception e)
{
logger.trace("Exception occured while closing the connection",e);
return false;
}
}
code : Invoking close method from another class
public closeConnection(){
this.wc.close();
System.exit(1);
}
Any help is appreciated :-)
Are you attempting to call
closeConnection
orclose
from a thread that belongs to the container or the container's ThreadPool / Executor?Also, once the container is stopped, all of the sessions will be stopped too.
Change
@ClientEndpoint
close()
to be ...And make
closeConnection()
simply ...A working example of this can be found at
https://github.com/joakime/javaxwebsocket-client-returncode
Which has the code ...
App.java
EchoEndpoint.java