Is there way to reuse Client after closing it?

It seems that if I close client with close-method, I can’t connect with it anymore.

Here’s how I get my problem:

  1. I connect to server (Connecting here works perfectly)
  2. After game ends, I call client’s close-method.
  3. I turn off server program
  4. I launch server program again
  5. I try to connect to new server exactly same way as in Step 1. This time however, it fails.

NOTE: I can connect to new server after restarting client-software

I noticed the following problem in logs:

WARNING: Root Cause: java.lang.IllegalStateException: Channels already exist.
WARNING: com.jme3.network.base.DefaultClient setPrimaryConnectors (DefaultClient.java:103)
WARNING: com.jme3.network.Network$NetworkClientImpl connectToServer (Network.java:188)
WARNING: com.jme3.network.Network$NetworkClientImpl connectToServer (Network.java:180)

It seems that closing client doesn’t remove the channels. I debugged my code in step 1 and 4 and noticed that client didn’t have any channels at step 1 but had 2 of them open in step 4.

Do I need to do something else besides closing client? For example, should I remove attached MessageListeners and StateListeners or do I need to create new Client-instance?

I’m using newest stable jMonkeyEngine platform on 64-bit Kubuntu 13.10.

Thanks in advance!

just create a new client every time you connect to the server.

Client is single use only. Once you close it then you throw it away. Just like a file stream if you want to think of it that way.

You have to create a new one each time you want to connect.

Ok thank you for your answers. I was able to refactor my code so that it creates new Client every time I need to connect. Everything works perfectly now.