Restarting client connection after disconnecting

Hello,

I’m working on a MMORPG and have a problem with starting the client after it’s closed due to disconnecting ([java]client.close()[/java])

I’m getting this error, but can’t find a way to fix it:

java.lang.IllegalThreadStateException
at java.lang.Thread.start(Thread.java:682)
at com.jme3.network.base.DefaultClient.start(DefaultClient.java:131)
at com.noblesofvictory.client.ClientMain.connect(ClientMain.java:116)
at com.noblesofvictory.client.MenuController.connect(MenuController.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at de.lessvoid.nifty.NiftyMethodInvoker.callMethod(NiftyMethodInvoker.java:145)
at de.lessvoid.nifty.NiftyMethodInvoker.performInvoke(NiftyMethodInvoker.java:104)
at de.lessvoid.nifty.Nifty$DelayedMethodInvoke.perform(Nifty.java:1174)
at de.lessvoid.nifty.Nifty.invokeMethods(Nifty.java:1152)
at de.lessvoid.nifty.Nifty.handleDynamicElements(Nifty.java:354)
at de.lessvoid.nifty.Nifty.access$1700(Nifty.java:77)
at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processEvent(Nifty.java:1374)
at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processMouseEvent(Nifty.java:1329)
at com.jme3.niftygui.InputSystemJme.handleMouseEvent(InputSystemJme.java:124)
at com.jme3.niftygui.InputSystemJme.onMouseButtonEventQueued(InputSystemJme.java:197)
at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:261)
at de.lessvoid.nifty.Nifty.update(Nifty.java:288)
at com.jme3.niftygui.InputSystemJme.endInput(InputSystemJme.java:113)
at com.jme3.input.InputManager.processQueue(InputManager.java:818)
at com.jme3.input.InputManager.update(InputManager.java:882)
at com.jme3.app.Application.update(Application.java:604)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:231)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)

i bet you have to create a client for each connection, they are not reusable. This doens’t mean that you have to restart the software of the client (human) just that you need to create a new instance of the client (class) and use it.

But your problem is maybe here : at com.noblesofvictory.client.ClientMain.connect(ClientMain.java:116)

(but, hey, without code the best thing i can do is guess)

1 Like

I had already tried that, but it still gives the same error:

[java]
public void disconnect() {
client.close();
try {
client = Network.connectToServer(ConnectionInfo.NAME,
ConnectionInfo.VERSION,
ConnectionInfo.HOST,
ConnectionInfo.PORT);
} catch (IOException e) {
Logger.getLogger(ClientMain.class.getName()).log(Level.SEVERE, null, e);
}
MessageInitializer.InitializeMessages(client, list);
[/java]

Which line gives the error? I assume this line

client = Network.connectToServer(ConnectionInfo.NAME,
ConnectionInfo.VERSION,
ConnectionInfo.HOST,
ConnectionInfo.PORT);

No sorry, that post was a bit vague. The error occurs when reconnecting to the server using [java]client.start()[/java].

ok well, if the thread is already started, you cannot start it again. You have to create a new thread, or change the values inside it (if you didn’t stop it). You cannot call start on a running thread.

I’ve got it working, thanks for the information. I made a mistake in the Auth handling when the password/ussername was wrong, so it didn’t call the disconnect method.