Note that there are some explanatory texts on larger screens.

plurals
  1. POAS3 Socket ProcessEvent.SOCKET_DATA seems not triggered
    primarykey
    data
    text
    <p>We use AS3 Event:ProcessEvent.SOCKET_DATA to listen for socket data. So this is my AS3 code for socket data handle.</p> <pre><code>private function packetHandler( e:ProgressEvent ):void { while( m_socket.bytesAvailable &amp;&amp; m_socket.bytesAvailable &gt;= pLen ) { //pLen means the packet length //pLen init is zero if( pLen == 0 ) { //PACKET_LEN stands for the solid length of one packet //PACKET_LEN = HEAD_LEN + 4 //the 4 means an unsigned int which means the packet content length if( m_socket.bytesAvailable &gt; PACKET_LEN ) { m_socket.readBytes( headByteBuffer, 0, HEAD_LEN ); headByteBuffer.clear(); pLen = m_socket.readUnsignedInt() + 4; } else { break; } } //recieved a whole packet now handle it else { var newPacket:ByteArray = new ByteArray(); newPacket.endian = Endian.LITTLE_ENDIAN; m_socket.readBytes( newPacket, 0, pLen ); parasMsg( newPacket, pLen-4 ); pLen = 0; } } } </code></pre> <p><strong>A whole packet can be described in this picture:</strong> <img src="https://i.stack.imgur.com/sOEmN.gif" alt="http://wuzhiwei.net/problems/packet.gif"></p> <p><strong>My Problem is: When there has one incomplete packet received in Flash and triggered the handle. But the left part of the packet will never trigger the handle and it seems like that the left part of the packet has lost!!!</strong></p> <p>I used a capture tool, find that the tcp packet is ok, but why the left part doesn't trigger the event again?</p> <p>You can get more debug information below. Thank you!</p> <p><strong>This is my log:</strong></p> <ul> <li>byteava means bytesAvailable of m_socket</li> </ul> <blockquote> <p>==>sendPacket: {"rangeID":"1","uid":"145962","serviceType":"copyscene","cmd":"CopySceneMoveAsk","pathPoint":[{"col":7,"row":6},{"col":7,"row":5},{"col":7,"row":4},{"col":7,"row":3},{"col":6,"row":3}],"sn":"79","smallPathPoint":[[22,19],[22,18],[22,17],[22,16],[22,15],[22,14],[22,13],[21,13],[21,12],[21,11],[20,11],[20,10]]}, bytesLoaded = 463</p> <p>ProgressEvent Triggered!0 socket byteava = 373 evt loaded:373 evt total:0 evt:[ProgressEvent type="socketData" bubbles=false cancelable=false eventPhase=2 bytesLoaded=373 bytesTotal=0]</p> <p>Find a packet from socket, pLen=288 socket byteava = 276</p> <p>ProgressEvent Triggered!288 socket byteava = 441 evt loaded:165 evt total:0 evt:[ProgressEvent type="socketData" bubbles=false cancelable=false eventPhase=2 bytesLoaded=165 bytesTotal=0]</p> <p>Start to Read a packet to buffer, pLen=288 socket byteava = 441</p> <p>whole packet content: Readed a packet to buffer, pLen=288 socket byteava = 153</p> <p>Server packet content byte buffer ava:288 len:288 pos: 0</p> <p>Server Paras Data : data len: 284 data content: {"cmd":"CopySceneMoveNotify","gtcmd":"108","layer":"1","pathPoint":[{"col":7,"row":6},{"col":7,"row":5},{"col":7,"row":4},{"col":7,"row":3},{"col":6,"row":3}],"smallPathPoint":[[22,19],[22,18],[22,17],[22,16],[22,15],[22,14],[22,13],[21,13],[21,12],[21,11],[20,11],[20,10]HTTP/1.1 200</p> </blockquote> <p><strong><code>_[20,10]HTTP/1.1 200_</code> This is what went wrong!! The incomplete packet cat with another packet's header.</strong></p> <p><strong>Here is the capture of the TCP connections:</strong> <img src="https://i.stack.imgur.com/VoV9b.jpg" alt="http://wuzhiwei.net/problems/captured_packets.jpg"></p> <p>Hope you can <strong>vote it up</strong> so that I can put my pictures of this question on!</p> <p>My English is not very good, hope you can understand what I mean. Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload