Skip to main content
Participant
October 18, 2011
Question

ServerSocket OSx problem

  • October 18, 2011
  • 2 replies
  • 1409 views

Hi,

I have an application that use flash.net.ServerSocket class, in my test suite when i reuse the address/port used by ServerSocket

the application fails with "#2002: Operation attempted on invalid socket.", these only appers to happen in OSx , in Windows 7 the

same test works fine.

Seem my test case bellow, the error happens the second time server.bind is called, any ideas, is there something wrong with that

code?

<?xml version="1.0" encoding="utf-8"?>

<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

                       xmlns:s="library://ns.adobe.com/flex/spark"

                       xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>

        <![CDATA[

            private var server:flash.net.ServerSocket;

            private var client:flash.net.Socket;

            private var i:int;

            public function init():void

            {

                i = 0;

                log.text = "";

                doTest();

            }

           

            public function doTest():void

            {

                try

                {

                    log.text += "socket " + i.toFixed() + "\n";

                    server= new ServerSocket();

                    server.addEventListener(Event.CLOSE, serverClose);

                    server.bind(10011, "127.0.0.1");

                    server.listen(511);

                   

                    client = new Socket();

                    client.addEventListener(Event.CONNECT, connected);

                    client.addEventListener(IOErrorEvent.IO_ERROR, ioError);

                    client.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError);

                    client.connect("127.0.0.1", 10011);

                    i++;

                }

                catch(ioe:IOError)

                {

                    log.text += ioe.toString() + "\n";

                }

                catch(e:Error)

                {

                    log.text += e.toString() + "\n";   

                }

            }

           

            public function ioError(e:IOErrorEvent):void

            {

                log.text += "IO error " + e.toString() + "\n";

            }

           

            public function securityError(e:SecurityErrorEvent):void

            {

                log.text += "Security error " + e.toString() + "\n";

            }

           

            public function connected(e:Event):void

            {

                server.close();

                if(i < 100)

                {

                    doTest();

                }

            }

           

            public function serverClose(e:Event):void

            {

                log.text += "Server close ok\n";

            }

        ]]>

    </fx:Script>

    <fx:Declarations>

        <!-- Place non-visual elements (e.g., services, value objects) here -->

    </fx:Declarations>

    <s:VGroup>

        <s:TextArea id="log" width="100%" height="100%">

           

        </s:TextArea>

        <s:Button click="init()" label="Start">

        </s:Button>

    </s:VGroup>

</s:WindowedApplication>

This topic has been closed for replies.

2 replies

Participant
November 8, 2011

Hello,

Can you confirm that this isn't a bug in AIR os-x?

If not a bug how can i explain that with other languages (C++, Java) this work perfectly well in OS X.?

Also AIR in windows after i have call close never get this problem, when try to bind again, but in OSx is easy easy to get this error after you have call close.

Bests,

Jose

Participant
October 18, 2011

My test case is bogus, because it don't call close in the socket received in

ServerSocketConnectEvent.

But even if i call close on it, i must wait too much time around 10 seconds or more, before a new Socket is able to bind to that host/port again, i just see that problem i OS X.

October 19, 2011

Hello,

Thanks for your reporting. The operation system does need some time to create a socket or close a socket. It may need more time to close a socket on Mac OS than that on Windows. To verify this, we just modify your code to make the "Start" only call the "doTest" once. Then we found if clicking "Start" fast on Windows, then "#2002: Operation attempted on invalid socket" would also appear, while if clicking "Start" slow on Mac OS, the application would work fine without the error. Please also have a try for that.

Thanks!

Participant
October 19, 2011

I work developing an RPC like library, that support multiple languages C++, C#, Python, Java among others a now ActionScript too, our test suite alwasys use the same ports "10000" and we run the tests in a loop this wasn't never a problem in OSx so seems to me that there is something more that affect the slowness on close the socket.

If that was an issue with the OS being slow closing the socket i would expect that affect other languages too, but we just see this problem with ActionScript tests.

Also if you just click start multiple times it could be that close was still not called? but i my case we try rebind after close has returned, so seems a different issue.

Also note that at the time the 2002 error happens, netstat report there isn't any active connection in that port, that seems odd.