Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 25-11-2003, 07:58   #1 (permalink)
Neuer User
 
Registriert seit: Jun 2003
Ort: Wien
Beiträge: 166
reconnect eines XMLSockets

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:
  1. SocketController.prototype  = new XMLSocket();
  2.  
  3. //  class constructor
  4. function SocketController (host, port) {
  5.   this._host = null;
  6.   this._port = 0;
  7.  
  8.   if (arguments.length > 1) {
  9.     this.setServer(host, port);
  10.   }
  11. }
  12.  
  13. //  try to establish connection to server
  14. SocketController.prototype.doConnect  = function() {
  15.   if (this._host == null || this._port < 1024) {
  16.     trace (Date() + ": Connection attempt aborted: invalid host or port!");
  17.     this.onConnectFailure();
  18.     return false;
  19.   } else {
  20.     debug_txt.text  = "before connect";
  21.     var connectSuccess  = this.connect(this._host, this._port);
  22.   }
  23.   if (connectSuccess) {
  24.     trace (Date() + ": initial connection succeeded. Awaiting server response ....");
  25.   } else {
  26.     trace (Date() + ": initial connection failed");
  27.     this.onConnectFailure();
  28.   }
  29. };
  30.  
  31. //  set host and port of server
  32. SocketController.prototype.setServer = function(host, port) {
  33.   if (typeof host != "string"
  34.       || typeof port != "number"
  35.       || (typeof port =="number" && port < 1024)) {
  36.      this._host  = null;
  37.      this._port  = false;
  38.      return false;
  39.   }
  40.    
  41.   this._host  = host;
  42.   this._port  = port;
  43. };
  44.  
  45. //  callback to respond to the completion of a connection attempt
  46. SocketController.prototype.onConnect  = function (success) {
  47.   if (success) {
  48.     trace (Date() + ": Connection to: " + this._host + ":" + this._port  + " established.");
  49.     this.onConnectSuccess();
  50.   } else {
  51.     trace (Date() + ": Connection to: " + this._host + ":" + this._port + " could not be established.");
  52.     this.onConnectFailure();
  53.   }
  54. };
  55.  
  56. //  callback invoked when server kills connection
  57. SocketController.prototype.onClose  = function() {
  58.   trace (Date() + ": server has terminated the connection. Flash GUI has been running " + getTimer()/60 + " s.");
  59.   this.onServerKillConnect();
  60. };
  61.  
  62. //  close the connection
  63. SocketController.prototype.killConnect  = function() {
  64.   trace ("Closing connection");
  65.   this.close();
  66.   this.onClientKillConnect();
  67. };
  68.  
  69. //  send Data to socket
  70. SocketController.prototype.socketSend = function(message) {
  71.   this.send(message);
  72. };

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
JuRo ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 06:07 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele