0 Replies Latest reply on Aug 15, 2011 1:31 PM by maretron

    What is the proper way to create a socket?

    maretron

      I am using Flash Professional CS5.5, and have the following code to connect to an IP camera.

       

      331:            // Connect to the camera using a Socket
      332:            this.webcamSocket = new Socket();
      333:            this.webcamSocket.addEventListener(Event.CONNECT, OnConnect); 
      334:            this.webcamSocket.addEventListener(ProgressEvent.SOCKET_DATA, OnData); 
      335:            this.webcamSocket.addEventListener(IOErrorEvent.IO_ERROR, OnIOError );
      336:            this.webcamSocket.connect(this.camera.IPAddress, PORT_NO);

       

      which works perfectly most of the time.

       

      The whole function is surrounded by a try {  } catch ( e : Error ) {  } block which is never triggered.

       

      However, every now and then, when the camera is unplugged or not present, the line

       

                  this.webcamSocket = new Socket();

       

      comes up with the following trace statements, and puts a window up for all to see ...

       

      Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.
          at MyVideo/Update()[AxisVideo::frame1:332]

          ....

       

      This means that it is possible for the Socket constructor to generate a SocketError.


      so

      1. What kind of error is the Socket Error ( IOErrorEvent does not list this as a constant )?

      2. If  you can only add event listeners after you create the Socket, how to do create an EventListener to catch this event in the constructor?

       

      Anyone?