Hi guys,
this may be a stupid question but I don’t know how to solve this problem (yes, I read the networking tutorial):
When I close my server
server.close();
this.addToConsole("Server closed. You may close this window now.");
I get the following exception at the client side:
Termining connection due to unhandled error
com.jme3.network.kernel.ConnectorException: Error reading from connection to:localhost/127.0.0.1:6600
at com.jme3.network.kernel.tcp.SocketConnector.read(SocketConnector.java:134)
at com.jme3.network.base.ConnectorAdapter.run(ConnectorAdapter.java:158)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.net.SocketInputStream.read(SocketInputStream.java:108)
at com.jme3.network.kernel.tcp.SocketConnector.read(SocketConnector.java:120)
... 1 more
I understand that the client throws an exception, I also tried working with ClientStateListener but I don’t really know how to use it or catch the exception otherwise…
I just want the client to go back into the main menu (or something like this) when the server closes instead of throwing this exception.
I would really much appreciate a little tip how to do this
Connection reset exception happens when the remote socket closed the connection. This is a natural behavior and will happen on client or on server.
Most game servers, when receive the server closing action, sends a close message to all clients. This avoid this kind of error and data loss, because clients will have time to close themselves and go to main menu before server close connection. Maybe you can do the same.
Well, I can’t comment on why your client state listener didn’t work because I can’t see it… but to avoid this issue you need to register a client state listener that detects that the client connection has closed and then somehow let the rest of the application know.
Exactly, there are a variety of reasons that the connection will go down other than the server desiring it… so one must handle the client state changes anyway.