diff --git a/jme3-networking/src/main/java/com/jme3/network/base/DefaultClient.java b/jme3-networking/src/main/java/com/jme3/network/base/DefaultClient.java index c0cc2e616..b297a933b 100644 --- a/jme3-networking/src/main/java/com/jme3/network/base/DefaultClient.java +++ b/jme3-networking/src/main/java/com/jme3/network/base/DefaultClient.java @@ -177,6 +177,10 @@ public class DefaultClient implements Client continue; send(ch, reg, false); } + } + + public boolean isStarted() { + return isRunning; } protected void waitForConnected() @@ -351,13 +355,16 @@ public class DefaultClient implements Client protected void fireConnected() { - // Let the services know we are finally started - services.start(); - for( ClientStateListener l : stateListeners ) { l.clientConnected( this ); } } + + protected void startServices() + { + // Let the services know we are finally started + services.start(); + } protected void fireDisconnected( DisconnectInfo info ) { @@ -416,11 +423,19 @@ public class DefaultClient implements Client // Pull off the connection management messages we're // interested in and then pass on the rest. if( m instanceof ClientRegistrationMessage ) { - // Then we've gotten our real id - this.id = (int)((ClientRegistrationMessage)m).getId(); - log.log( Level.FINE, "Connection established, id:{0}.", this.id ); - connecting.countDown(); - fireConnected(); + ClientRegistrationMessage crm = (ClientRegistrationMessage)m; + // See if it has a real ID + if( crm.getId() >= 0 ) { + // Then we've gotten our real id + this.id = (int)crm.getId(); + log.log( Level.FINE, "Connection established, id:{0}.", this.id ); + connecting.countDown(); + fireConnected(); + } else { + // Else it's a message letting us know that the + // hosted services have been started + startServices(); + } return; } else if( m instanceof ChannelInfoMessage ) { // This is an interum step in the connection process and diff --git a/jme3-networking/src/main/java/com/jme3/network/base/DefaultServer.java b/jme3-networking/src/main/java/com/jme3/network/base/DefaultServer.java index 0a9ac0ef1..97e36134e 100644 --- a/jme3-networking/src/main/java/com/jme3/network/base/DefaultServer.java +++ b/jme3-networking/src/main/java/com/jme3/network/base/DefaultServer.java @@ -412,7 +412,14 @@ public class DefaultServer implements Server // Now we can notify the listeners about the // new connection. - fireConnectionAdded( addedConnection ); + fireConnectionAdded( addedConnection ); + + // Send a second registration message with an invalid ID + // to let the connection know that it can start its services + m = new ClientRegistrationMessage(); + m.setId(-1); + m.setReliable(true); + addedConnection.send(m); } }