use of com.jme3.network.ClientStateListener.DisconnectInfo in project jmonkeyengine by jMonkeyEngine.
the class DefaultClient method dispatch.
protected void dispatch(Message m) {
if (log.isLoggable(Level.FINER)) {
log.log(Level.FINER, "{0} received:{1}", new Object[] { this, m });
}
// interested in and then pass on the rest.
if (m instanceof ClientRegistrationMessage) {
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();
// Delay firing 'connected' until the services have all
// been started to avoid odd race conditions. If there is some
// need to get some kind of event before the services have been
// started then we should create a new event step.
fireConnected();
}
return;
} else if (m instanceof ChannelInfoMessage) {
// This is an interum step in the connection process and
// now we need to add a bunch of connections
configureChannels(((ChannelInfoMessage) m).getId(), ((ChannelInfoMessage) m).getPorts());
return;
} else if (m instanceof DisconnectMessage) {
// Can't do too much else yet
String reason = ((DisconnectMessage) m).getReason();
log.log(Level.SEVERE, "Connection terminated, reason:{0}.", reason);
DisconnectInfo info = new DisconnectInfo();
info.reason = reason;
closeConnections(info);
}
// thread simultaneously.
synchronized (this) {
messageListeners.messageReceived(this, m);
}
}
use of com.jme3.network.ClientStateListener.DisconnectInfo in project jmonkeyengine by jMonkeyEngine.
the class DefaultClient method handleError.
/**
* Either calls the ErrorListener or closes the connection
* if there are no listeners.
*/
protected void handleError(Throwable t) {
// a reason
if (errorListeners.isEmpty()) {
log.log(Level.SEVERE, "Termining connection due to unhandled error", t);
DisconnectInfo info = new DisconnectInfo();
info.reason = "Connection Error";
info.error = t;
closeConnections(info);
return;
}
for (ErrorListener l : errorListeners) {
l.handleError(this, t);
}
}
Aggregations