Server and client version: how to detect mismatch?

Hi monkeys! I need help with creating a server (this question is more related do @pspeed, since it was him that programmed the classes):

When the version and game name of the client and server are different, the server does not let the client connect to it. That’s good. However, it doesn’t close the app or show a window with a error, so my game keeps opened. I tried to use the method isConnected() from the client, but it’s always returning false, althought my server tells me that someone is connected. So, I tried to look in the code of the Network, DefaultServer, DefaultClient and other classes to find where is the exception thrown. However I can’t find it anywere, so I need help from you guys!

Thanks,
Ev1lbl0w

In the “teach a man to fish” vein, take a look at the javadoc for Client and see if you can figure out how you might listen for errors.

addErrorListener(ErrorListener<? super Client> listener);

I suppose it’s this. Thanks for the help!

BTW, @pspeed, In the networking wiki, it says i should close the client in the destroy() method. However I am using AppStates, and calling close() in cleanUp() doesn’t work. What do I do?

That would depend on what “doesn’t work” means. I agree that’s the best way. Personally, I’d avoid doing what the wiki says because it’s better for the connection to be managed by an app state as you are doing and once the app is closing there is relatively little point in shutting down the connection (depending on how aggressively the app is closing).

Thanks for the reply, @pspeed
Before, when I tried to close the app, it would open a window saying something like “The client is not started”. However, it is not appearing anymore. I don’t know… The server never had a problem like that. Only the client.

The code on the cleanUp method on the client:

 @Override
public void cleanup() {
    client.close();

    super.cleanup();
}

The code on the cleanUp method on the server:

@Override
public void cleanup() {
    server.close();

    super.cleanup();
}

On the client you shouldn’t try to close the connection unless it’s actually started… or you will get that error. The key would be not to attach the app state that closes client until the client is actually started.

Usual pattern: have a ClientConnectionAppState or whatever that is attached based on the ClientStateListener getting notified that the connection is actually started. (Or you could always attach it and do it on disable instead.)

…but the key would be to have the app state that calls client.close() not to even call that if the client was never started.

1 Like

Thanks for the tip, @pspeed!