2 Replies Latest reply: Jun 9, 2010 2:01 PM by sneakyimp RSS

    data written to socket getting lost?  or perhaps out of order?

    sneakyimp Community Member

      I'm trying to fix a bug in Flashmog. The bug is described in more detail here.

       

      Basically what is happening is that my Flash client claims that it is calling functions that don't arrive at the server -- or they arrive, but the socket data is out of order and therefore is garbled.  I've stared at the source code for hours and tried a lot of trial-and-error type stuff and added trace statements to see if I can find the problem and I'm not having any luck.

       

      In particular, there's class I have called RPCSocket that extends the AS3 Socket class so I can serialize data structures before sending them across a socket.  At one point, this RPCSocket class calls super.writeBytes and super.Flush.  It is the point at which I send all data out of my client. The data is binary data in AMF3 format.

                public function executeRPC(serviceName:String, methodName:String, methodParams:Array):void {
                     if (!this.connected) {
                          log.write('RPCSocket.executeRPC failed. ' + methodName + ' attempted on service ' + serviceName + ' while not connected', Log.HIGH);
                          throw new Error('RPCSocket.executeRPC failed. ' + methodName + ' attempted on service ' + serviceName + ' while not connected.');
                          return;
                     }
                     var rpc:Array = new Array();
                     rpc[0] = serviceName;
                     rpc[1] = methodName;
                     rpc[2] = methodParams;
                     var serializedRPC:ByteArray = serialize(rpc);
                     if (!serializedRPC) {
                          log.write('RPCSocket.executeRPC failed.  Serialization failed for method ' + methodName + ' on service ' + serviceName, Log.HIGH);
                          dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR, false, false, 'RPCSocket.executeRPC failed.  Serialization failed for method ' + methodName + ' on service ' + serviceName));
                     }
                     super.writeUnsignedInt(serializedRPC.length);
                     super.writeBytes(serializedRPC);
                     super.flush();
                } // executeRPC

       

      Can someone recommend a way for me to store without corruption, conversion, or filtering or translation of any kind *all* of the information sent across this socket? I'd like to write it to a file.  I'm guessing that keep a global ByteArray var and storing the info there might work, but I'm wondering how I might get the contents of that ByteArray into a file so I can inspect it.

       

      Also, I'm wondering if I might be able to inspect what flash actually sends out on the socket?  I have a sneaking suspicion that data I supply to super.writeBytes may be sent out of order or may not actually get sent across the socket.  This bug I'm talking about only seems to happen under high-stress situations when I'm sending dozens of messages per second across this one socket.