[Solved] Client crashes after Server crash

Hi,



I have the problem that my client crashes after its connection to the server was cut (due to unexpected server shutdown),

I get the following output:



[java]21.06.2012 21:28:05 com.jme3.network.base.DefaultClient handleError

SCHWERWIEGEND: Termining connection due to unhandled error

com.jme3.network.kernel.ConnectorException: Error reading from connection to:localhost/127.0.0.1:30100

at com.jme3.network.kernel.tcp.SocketConnector.read(SocketConnector.java:135)

at com.jme3.network.base.ConnectorAdapter.run(ConnectorAdapter.java:159)

Caused by: java.net.SocketException: Connection reset

at java.net.SocketInputStream.read(Unknown Source)

at java.net.SocketInputStream.read(Unknown Source)

at com.jme3.network.kernel.tcp.SocketConnector.read(SocketConnector.java:121)

… 1 more

[/java]



Do you have any suggestions of what I can do to catch this exception and prevent the client crash?



Greetings,

Daniel

…like you say, catch the exception?

[java]

try{

//do network stuffs

}

catch(ConnectorException e){

//handle exception

}

[/java]

Standard java knowledge, really.

That’s obvious, even for me :wink:



The problem is, that I can’t find the right place to catch the exception.



Simplified client code:



[java]public void start(){

try {

client = Network.connectToServer(config.getNameSM(), config.getVersionSM(), config.getIpAddressSM(), config.getPortTcpSM());

client.start();

registerSerializableClasses();

client.addMessageListener(this);

} catch (IOException e) {

LOGGER.warn("Unable to connect to server, due to error: " + e.getMessage());

throw new ClientNotStartableException(e);

}

} [/java]



Even when I just call this simplified method and don’t have any messages send between the client and the server, I get my client crashed, when the server crashes.



I think that one of the threads started by the network classes runs in the exception and so I just don’t know where I could catch the exception…

You can add an error listener to the client.

http://hub.jmonkeyengine.org/javadoc/com/jme3/network/Client.html#addErrorListener(com.jme3.network.ErrorListener)



The actual networking is done on background threads so there is no way to try/catch anything. When you send() a message it’s actually just sticking it into an outbound queue.

1 Like

Thanks a lot.

That was exactly what I needed. :slight_smile: