Komak57

packetstrip

Oct 22nd, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. private var buf:ByteArray = new ByteArray();
  3. private var sbuf:ByteArray = new ByteArray();
  4. protected function voiceReceive(event:ProgressEvent):void
  5. {
  6.     var avail:uint = VoiceSock.bytesAvailable;
  7.     trace("voice received "+avail+".");
  8.     if (avail > 0) {
  9.         // get bytes from socket, write to buffer
  10.         VoiceSock.readBytes(sbuf); // buffer socket data
  11.         // reset position
  12.         sbuf.position = 0;
  13.        
  14.         // get ID
  15.         var _id:ByteArray = new ByteArray();
  16.         _id.writeBytes(sbuf, 0, 4);
  17.         _id.position = 0;
  18.         var id:int = _id.readInt();
  19.         // get data LEN
  20.         var _len:ByteArray = new ByteArray();
  21.         _len.writeBytes(sbuf, 4, 4);
  22.         _len.position = 0;
  23.         var len:int = _len.readInt();
  24.         if (id < 0 || len < 0)
  25.             return;
  26.         // check/create new user control
  27.         if (!sounds.containsKey(id)) {
  28.             sounds.put(id, new SoundObj());
  29.         }
  30.         if (sbuf.length >= 8+len) {
  31.             // read data
  32.             var buf:ByteArray = new ByteArray();
  33.             buf.writeBytes(sbuf, 8, len);
  34.            
  35.             // crop used data
  36.             var _buf:ByteArray = new ByteArray();
  37.             _buf.writeBytes(sbuf, 8+len, sbuf.length-(8+len));
  38.             sbuf = _buf;
  39.             // write all but ID bytes to specialized buffer
  40.             sounds.get(id).receive(buf);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment