Recieving events when server quits

hello,



i’d like to know whether there is a way to get something of an event or such when the server is closed. the client has got MessageListener implemented and recieves a me.codeninja.spidermonkey.message.DisconnectMessage. However, the MessageListener implemented into my class does not do so. Furthermore, when the application that contains the server is terminated, an exception is thrown.



java.io.IOException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233)
at sun.nio.ch.IOUtil.read(IOUtil.java:200)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:236)
at me.codeninja.spidermonkey.connection.TCPConnection.read(TCPConnection.java:104)
at me.codeninja.spidermonkey.connection.Connection.run(Connection.java:92)
at me.codeninja.spidermonkey.connection.ConnectionRunnable.run(ConnectionRunnable.java:47)
at java.lang.Thread.run(Thread.java:619)
06.10.2010 17:29:42 me.codeninja.spidermonkey.connection.Connection run


I'm sorry. The exception message is in German for my PC. Is there something I can do to prevent this??
Thanks,
Fellkneul

Have you registered the listener to the client? It’s quite a common mistake :stuck_out_tongue:



About the exception, it’s weird - I’ve tried this situation numerous times (client and server killing) but I’ve not come across this problem. How specifically are you killing the server? (What command, e.g.)

About registering the listener… Do you mean the addMessageListener method?? That’s what I did. Otherwise, I didn’t. Is there something else I’m supposed to do with the MessageListener?? However, it recieves other instances of classes I have written myself and which are subclasses to Message.



About the exception: It would only occur when I press the eclipse button “terminate programm”. In my game there is a “Quit” button which would shut down all processes and call server.stop();. In this case my client could listen to the DisconnectMessage and shut down nicely.

Do you use Netbeans or eclipse?? I don’t know what it’s like in NetBeans but in eclipse you can simply terminate a call with a press to the red square (terminate button). I believe it would simply stop all processes, close all Streams, close the socket etc. Is there no way to simply catch the exception that is thrown?? Maybe surround the socket-reading code in a try. So when an IOException is thrown from the TCPConnection.read() Method, you could call the clientDisconnect method and set the reason to something like “UnexpectedDisconnect”?? You know what I mean??



I’m sorry I’m currently not working and my home pc so I do not have much access to the source codes…



gz,

Fellkneul

There’s no actual problem with catching the exception, it’s just that I haven’t been able to reproduce the problem yet. I’ll test some more here and there, and see what I can come up with. I’ll let you know how it goes.



Edit: I did quite a lot of testing, killing the server in different ways, even while it was sending hundreds of messages a second, but could still not reproduce the problem. Any chance you can paste some code? Thanks!