Here's the code I've been using to try and reproduce the disconnect. I'm running on Windows 7, the server is using ActivePython 2.6 and my AIR apps have been built with Flex 4.1 / AIR 2 and running on AIR 2.0.3 runtime. No luck so far... chat.py # import socket and select module
import socket, select
# define checkData function that is the core of our Socket comunication
def checkData():
#create an infinitive loop to check data from an AIR client to another one
while True:
# use select module to allow an application to wait for input from multiple sockets at a time
inputready,outputready,exceptready = select.select(input,[],[])
for s in inputready:
if s == theSock:
# add a client to the socket connection
client, address = theSock.accept()
input.append(client)
else:
try:
# comunication between client and server: manage traffic data
data = s.recv(1024)
# in tempConn we put all client without server connection
tempConn = input[1:len(input)]
if data:
for i in tempConn:
# send to all client any messages
i.send(str(i.getsockname()[0]) + ": " + data)
else:
client.close()
input.remove(s)
except socket.error, e:
# Remove
inputs.remove(s)
#define socket connection: address, port and type of socket connection
theAddress = ('localhost',1024)
theSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
theSock.bind(theAddress)
theSock.listen(5)
input = [theSock]
#after established XMLSocket connection, manage messages from client
checkData() and XMLSocketTest.mxml <?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"
creationComplete="init()"
showStatusBar="false">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.utils.getTimer;
private var srv:XMLSocket;
private var ping:Timer = null;
private var startTime:Number;
private function init():void
{
startTime = getTimer();
srv = new XMLSocket();
srv.addEventListener(Event.CLOSE, closeHandler);
srv.addEventListener(Event.CONNECT, connectHandler);
srv.addEventListener(DataEvent.DATA, dataHandler);
srv.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
srv.addEventListener(ProgressEvent.PROGRESS, progressHandler);
srv.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
srv.connect("localhost", 1024);
}
private function progressHandler(e:Event):void
{
chatOutput.text += "ProgressEvent.PROGRESS \n";
}
private function securityErrorHandler(e:Event):void
{
chatOutput.text += "SecurityErrorEvent.SECURITY_ERROR \n";
exitChat();
}
private function closeHandler(e:Event):void
{
chatOutput.text += "Event.CLOSE \n";
exitChat();
}
private function exitChat():void
{
var endTime:Number = getTimer();
var totalSeconds:Number = (endTime - startTime) / 1000;
chatOutput.text += "Total Time: " + totalSeconds + " seconds \n";
if (ping)
ping.stop();
}
private function connectHandler(e:Event):void
{
chatOutput.text += "Event.CONNECT \n";
// Start the ping timer
ping = new Timer(5000);
ping.addEventListener("timer", pingHandler);
ping.start();
}
public function pingHandler(event:TimerEvent):void
{
srv.send("pong");
}
private function ioErrorHandler(e:IOErrorEvent):void
{
chatOutput.text += e.text + "\n";
exitChat();
}
private function dataHandler(e:DataEvent):void
{
chatOutput.text += e.data + "\n";
}
private function sendMessage():void
{
srv.send(chatInput.text);
chatInput.text = "";
}
]]>
</fx:Script>
<mx:VBox width="100%" height="100%">
<mx:TextArea id="chatOutput" editable="false" width="100%" height="100%" valueCommit="chatOutput.verticalScrollPosition=chatOutput.maxVerticalScrollPosition" />
<mx:HBox width="100%">
<mx:TextInput id="chatInput" width="100%" enter="sendMessage()"/>
<mx:Button label="Send" click="sendMessage()"/>
</mx:HBox>
</mx:VBox>
</s:WindowedApplication>
... View more