ServerSocket OSx problem
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>
