Question

I'm trying to write a very plain game client to get some practice with Actionscript 3 and the Flex Framework.

I have some problems with following code:

private function readResponse():void {
   var r:ByteArray =  new ByteArray();
   readBytes(r);
   while (r.bytesAvailable != 0)
   {
    try
    {
     var d:Object = r.readObject();
     protocol.execute(d); // do something with the object
    }
    catch (RangeError)
    {
     trace("Ouch, packet dismissed? Restlength:" + r.bytesAvailable);
    }
   }
  }

It seems to work well in the client most of the time, but sometimes i got strange a behavior that shouldn't occure. If i look in the console output, there are many of "dismissed" packets. Once i logged the discarded rest of the package, it very looks like a broken, uncomplete packet. It starts in the middle of a string e.g. It often occurs if data is send rapidly from the server. On serverside, each of the packets are send by calling the related client.send() function.

Is this the wrong way to try handling more than one object incoming? Could this be a serverside issue, causing the packets to be send malformed/incomplete?

I would be very happy if someone can help me out.

Little update, maybe this helps: I logged the length of data send over the network. The logged looks like this (server | client):
208 | 208
92 | 92
208 | 208 214 | 214 & Ouch, packet dismissed? Restlength:: 212
148 | r.bytesAvailable: 388
27 | 388 & Ouch, packet dismissed? Restlength:: 384 etc...

This looks like the server bursts data and the client is messing up with this. What could i post more to get some help with this issue? Do i have to flush data manualy on the python server to get things work right? I'm not really sure what is happening. I just know that this happens mostly if I'm doig a lot of client.send() very very fast, like it get buffered and then send in the size of the buffer, so it cuts the packet into a few not readable for the client (because obviously it doesn't expect this). I'm really stuck with this :(

PS: The server is written in Python with an usual tutorial-like TCP socket and client threads.

No correct solution

OTHER TIPS

If you are using AMF, I do not understand why you would read bytes from a binary array?

Try using RemoteObject, and a response-handler ( and eventually also an error handler )

There is an example here: http://pyamf.org/tutorials/actionscript/simple.html#actionscript (which I have not tried as I am not python savvy)

Other than that, remember that commands are fire and forget. The major part of issues encountered in dealing with server side traffic in Flex is caused by not registering event listeners etc. pr. server call.

Hope it helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top