Before a client can do anything with the server a connection must be established.
More...
Before a client can do anything with the server a connection must be established.
When connectinghave the ability to specify a series of connections to attempt. They are attempted in order until one succeeds or they all fail. As each connection individually succeeds or fails a ConnectionAttemptResponse event is fired off. Once a connection succeeds or they all fail, a ConnectionResponse event is fired off.
package {
import flash.display.Sprite;
import flash.events.Event; //ElectroServer imports
import com.electrotank.electroserver5.api.ConnectionAttemptResponse;
import com.electrotank.electroserver5.api.ConnectionResponse;
import com.electrotank.electroserver5.api.MessageType;
import com.electrotank.electroserver5.ElectroServer; //Logger imports
import mx.logging.Log;
import mx.logging.targets.TraceTarget; public class Main extends Sprite {
private var _es:ElectroServer = new ElectroServer();
public function Main():void {
//add this so we can see the logs get traced
Log.addTarget(new TraceTarget());
//load settings file and connect
_es.loadAndConnect("settings.xml");
//listen to key events to know when a connection has succeeded or failed
_es.engine.addEventListener(MessageType.ConnectionResponse.name, onConnectionResponse);
_es.engine.addEventListener(MessageType.ConnectionAttemptResponse.name, onConnectionAttemptResponse);
}
private function onConnectionAttemptResponse(e:ConnectionAttemptResponse):void {
trace("Connection attempt success: " + e.successful.toString());
if (!e.successful) {
trace(e.error.name);
}
}
private function onConnectionResponse(e:ConnectionResponse):void {
trace("Connection success: " + e.successful.toString());
if (!e.successful) {
trace(e.error.name);
}
}
}
}