Hi,
Folgendes Problem. Ich habe eine Server-Client Anwendung, wo sich das Flash (als Standalone-player) an einem Java-Server anmeldet. Hier ist meine SocketController-Klasse, die die Verbindung "verwaltet".
ActionScript:
SocketController.prototype = new XMLSocket();
// class constructor
function SocketController (host, port) {
this._host = null;
this._port = 0;
if (arguments.length > 1) {
this.setServer(host, port);
}
}
// try to establish connection to server
SocketController.prototype.doConnect = function() {
if (this._host == null || this._port < 1024) {
trace (Date() + ": Connection attempt aborted: invalid host or port!");
this.onConnectFailure();
return false;
} else {
debug_txt.text = "before connect";
var connectSuccess = this.connect(this._host, this._port);
}
if (connectSuccess) {
trace (Date() + ": initial connection succeeded. Awaiting server response ....");
} else {
trace (Date() + ": initial connection failed");
this.onConnectFailure();
}
};
// set host and port of server
SocketController.prototype.setServer = function(host, port) {
if (typeof host != "string"
|| typeof port != "number"
|| (typeof port =="number" && port < 1024)) {
this._host = null;
this._port = false;
return false;
}
this._host = host;
this._port = port;
};
// callback to respond to the completion of a connection attempt
SocketController.prototype.onConnect = function (success) {
if (success) {
trace (Date() + ": Connection to: " + this._host + ":" + this._port + " established.");
this.onConnectSuccess();
} else {
trace (Date() + ": Connection to: " + this._host + ":" + this._port + " could not be established.");
this.onConnectFailure();
}
};
// callback invoked when server kills connection
SocketController.prototype.onClose = function() {
trace (Date() + ": server has terminated the connection. Flash GUI has been running " + getTimer()/60 + " s.");
this.onServerKillConnect();
};
// close the connection
SocketController.prototype.killConnect = function() {
trace ("Closing connection");
this.close();
this.onClientKillConnect();
};
// send Data to socket
SocketController.prototype.socketSend = function(message) {
this.send(message);
};
Wie kann ich dem Client folgdendes sagen:
1. probier dich so lange alle X sek zu reconnecten, bis du erfolgreich warst
2. wenn die Verbindung unterbrochen wird, mach sofort einen reconnect.
Kommentare, Anregungen, usw sind erwünscht!
mfg
Juro