1 Reply Latest reply on Apr 18, 2008 11:14 AM by enorton@adobe

    SocketMonitor not working as expected

    MarcelBoucher Adobe Employee
      I created a simple AIR application that uses SocketMonitor to check the availability of ports on the local machine. When I call my function, I pass in the server name and the port (ex. "localhost", 3306). This code works the first time I launch the app (if MySQL is running, I get a true value. But if I stop the service, nothing changes in my AIR app. The "available" property always returns true. Also, if I try to set the pollInterval property of SocetMonitor, the app crashes. I am using the following code:

      public var socketAvailable:Boolean=false;
      public var mysocket:SocketMonitor;

      public function startPortCheck(serverName:String, portNumber:int):void
      {
      mysocket = new SocketMonitor(serverName,portNumber);
      mysocket.start();
      mysocket.addEventListener(StatusEvent.STATUS,socketStatusChange);
      }

      public function socketStatusChange(event:StatusEvent):void
      {
      trace( ">>onStatusEvent::evt.code=" + event.code );
      socketAvailable = mysocket.available;
      }

        • 1. Re: SocketMonitor not working as expected
          enorton@adobe Level 1
          Hi Marcel,

          The monitors check when there is a NetworkStatusChange. If you want more frequent checks, you should definitely use pollInterval. I'm not able to reproduce a crash with pollInterval & the SocketMonitor. What pollInterval have you tried? Is this with localhost? Is it right away or eventually after a few polls? What platform are you running?

          One tiny thing though, you should .start() after the .addEventListener. You want to make sure you catch all dispatches...if you start before listening you could miss one.

          -Erica