I'm working on the project in AIR (AS3). I have a Socket Server running on my computer, and two ipads connected over wifi, which should communicate with the server. I wrote a basic "send" function which works this way :
function send(_type:String, _data:String):void
{
socket.writeObject({ type: _type, data: _data});
socket.flush();
}
When the server reads a response, it just sends it to the other socket (ipad) to achieve indirect ipad-to-ipad communication. The port is above 1024.
Sometimes, especially when both ipads send a message at approximately the same time, nothing is sent back from the server. I colleague working on a different project but with AIR AS3 sockets use WriteUTFBytes/readUTFBytes instead of my writeObject/readObject and he doesn't seem to have this problem.
My question is basically, is there a fundamental difference between these two functions ? How can I prevent this bug ? I'm suspecting that somehow the server doesn't like to send a message on a socket currently carrying another message. Am I right ?
Update: Server side message handling :
I have a listener for the ProgressEvent.SOCKET_DATA event, which looks like this :
private function onData(e: ProgressEvent):void
{
var currentSocket:Socket = e.currentTarget as Socket;
var p:Object = currentSocket.readObject();
switch(p.type)
{
// Process data based on the type of event
}
}
Update 2 : I've done some debugging with Wireshark, and I've noticed that sometimes, my flash trace says it sent the message, and it doesn't appear in Wireshark (which shows PDU fragment, so I guess even merged packages should show up).
Second thing (third update), is when both ipads send a message at the same time, they are properly shown in Wireshark but the server only reads the first one ! Although both ACK are presents. I don't understand.