Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6153877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:10:00+00:00 2026-05-23T20:10:00+00:00

Does anyone know why the Close Event is not dispatched after I disconnect my

  • 0

Does anyone know why the Close Event is not dispatched after I disconnect my wifi connection? Or any way to determine if the connection is active.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:10:00+00:00Added an answer on May 23, 2026 at 8:10 pm

    Not sure you need to implicately close it but I do on the close callback

    _socket.addEventListener(Event.CLOSE, onClose);
    
    private function onClose(e:Event):void {
      _socket.close();
    }
    

    You can also test during connection time to make sure it is not already connected

    if( !_socket.connected ){
      try {
        _socket.connect(host, port);
        this.dispatchEvent( new Event( 'CONNECTING' ) );
      } catch (e:Error) {
        _socket.close();
        this.dispatchEvent( new Event( 'ERROR' ) );
      }
    }
    

    [EDIT]
    When connection is lost to the server a connection closed event will not fire, you have to test for this if you want to reconnect.
    To do this you need to set up a timer to poll the connection. The following class will continue to pole the socket and if it is found not connected it will try to reconnect.

    I stripped down and removed the send functions and non-relative info.
    As you can see I have a timer that poles the socket and will also time out after so many retries.
    This class will try to keep your socket alive if it gets closed.
    Obviously you need to assign port and host.

    package{
      import flash.events.Event;
      import flash.events.IOErrorEvent;
      import flash.events.ProgressEvent;
      import flash.events.SecurityErrorEvent;
      import flash.events.TimerEvent;
      import flash.net.Socket;
      import flash.system.Security;
      import flash.utils.Timer;
    
      public class MySocket extends Socket {
        [Event(name="ERROR")]
        [Event(name="CONNECTED")]
        [Event(name="DISCONNECTED")]
        [Event(name="CONNECTING")]
        [Event(name="TIMIEDOUT")]
    
        private var host:String;
        private var port:Number;
        private var connectTimer:Timer;
        private var retryCount:int;
    
        public var err:String;
    
        public function MySocket(  ){
          this.retryCount = 0
          Security.allowDomain(this.host);
          Security.loadPolicyFile("xmlsocket://"+this.host+":"+this.port);
          this.addEventListener(ProgressEvent.SOCKET_DATA, this.onResponse);
          this.addEventListener(Event.CONNECT, this.onConnect);
          this.addEventListener(Event.CLOSE, this.onClose);
          this.addEventListener(IOErrorEvent.IO_ERROR, this.onIOError);
          this.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onSecurityError);
          this.dispatchEvent( new Event( 'DISCONNECTED' ) );
          this.err = '';
          this.connectTimer = new Timer( 1000 );
          this.connectTimer.addEventListener(TimerEvent.TIMER, this.myConnect );
          this.connectTimer.start();
        }
    
        private function onResponse(e:ProgressEvent):void {
          var read:String = this.readUTFBytes(this.bytesAvailable );
          if( read.charAt(0) !='<' ){
            if( read ){
              // the server response here
            }
          }else{
            // recieved crossdomain policy do nothing
          }
        }
        public function myConnect( e:TimerEvent ):void{
          if( !this.connected ){
            try {
              this.connect(this.host, this.port);
              this.dispatchEvent( new Event( 'CONNECTING' ) );
            } catch (e:Error) {
              this.close();
              this.err = e.message;
              this.dispatchEvent( new Event( 'ERROR' ) );
            }
          }
        }
        private function onConnect(e:Event):void {
          this.retryCount = 0
          this.err = '';
          this.dispatchEvent( new Event( 'CONNECTED' ) );
        }
        private function onClose(e:Event):void {
          this.close();
          this.dispatchEvent( new Event( 'DISCONNECTED' ) );
        }
        private function onIOError(e:IOErrorEvent):void {
          ++this.retryCount;
          if( this.retryCount >= 12 ){
            this.connectTimer.stop();
            this.dispatchEvent( new Event( 'TIMIEDOUT' ) );
          }else{
            this.err = 'IO-ERROR-EVENT - ' + e.text + '\r\nAttempting to reconnect';
          }
        }
        private function onSecurityError(e:SecurityErrorEvent):void {
          this.err = 'SECURITY-ERROR - ' + e.text;
          this.dispatchEvent( new Event( 'ERROR' ) );
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of any (free) tools that will convert an old Delhi 5
Does any one know why this is not working? http://jsfiddle.net/jonevar/2Z2NQ/5/ Here is the whole
Does anyone know a 100% clone of the C/C++ printf for Delphi? Yes, I
Does anyone know how to change icons in Silverlight outofbrowser application?
Does anyone know if views states (used in Silverlight) will be available in next
Does anyone know how to add an item to a list but do it
Does anyone know of a "similar words or keywords" algorithm available in open source
Does anyone know of an equivalent to FxCop/StyleCop for Delphi? I would really like
Does anyone know how I can go about hiding the tab selectors for the
Does anyone know a Library which provides a Thread.sleep() for Java which has an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.