Modified the DefaultServer to send a second client

info message to indicate that all of the local hosted
services have been notified about the new connection.
Modified DefaultClient to wait to start its services
until it has seen this second message.

Client services may want to send things to the server during
their start() method but it's important that things like
the serializer registry service has already processed its
messages or any sends might fail.  The client generally has
the luxury of being able to register handlers/listeners/etc
during initialize where as the server must do this when the
connection arrives.  So it seems reasonable to delay client
service start() until all of the server-side hosted services
have had a chance to initialize themselves.
experimental
Paul Speed 10 years ago
parent d3c644123a
commit 57dbf384a2
  1. 31
      jme3-networking/src/main/java/com/jme3/network/base/DefaultClient.java
  2. 9
      jme3-networking/src/main/java/com/jme3/network/base/DefaultServer.java

@ -177,6 +177,10 @@ public class DefaultClient implements Client
continue; continue;
send(ch, reg, false); send(ch, reg, false);
} }
}
public boolean isStarted() {
return isRunning;
} }
protected void waitForConnected() protected void waitForConnected()
@ -351,13 +355,16 @@ public class DefaultClient implements Client
protected void fireConnected() protected void fireConnected()
{ {
// Let the services know we are finally started
services.start();
for( ClientStateListener l : stateListeners ) { for( ClientStateListener l : stateListeners ) {
l.clientConnected( this ); l.clientConnected( this );
} }
} }
protected void startServices()
{
// Let the services know we are finally started
services.start();
}
protected void fireDisconnected( DisconnectInfo info ) protected void fireDisconnected( DisconnectInfo info )
{ {
@ -416,11 +423,19 @@ public class DefaultClient implements Client
// Pull off the connection management messages we're // Pull off the connection management messages we're
// interested in and then pass on the rest. // interested in and then pass on the rest.
if( m instanceof ClientRegistrationMessage ) { if( m instanceof ClientRegistrationMessage ) {
// Then we've gotten our real id ClientRegistrationMessage crm = (ClientRegistrationMessage)m;
this.id = (int)((ClientRegistrationMessage)m).getId(); // See if it has a real ID
log.log( Level.FINE, "Connection established, id:{0}.", this.id ); if( crm.getId() >= 0 ) {
connecting.countDown(); // Then we've gotten our real id
fireConnected(); 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; return;
} else if( m instanceof ChannelInfoMessage ) { } else if( m instanceof ChannelInfoMessage ) {
// This is an interum step in the connection process and // This is an interum step in the connection process and

@ -412,7 +412,14 @@ public class DefaultServer implements Server
// Now we can notify the listeners about the // Now we can notify the listeners about the
// new connection. // 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);
} }
} }

Loading…
Cancel
Save