In the actual project, as3 implements a tcpclient object. It should be okay to use flash.net. socket to implement a tcpclient. Let me talk about some people who don't pay attention to the issues.
1. byte order
When I was working on a project with two client colleagues, they didn't fully understand this byte sequence.
The socket in as3 contains functions similar to readshort () & writeshort.
Let's talk about writeshort (). For example, we call the followingCode:
Socket. writeshort (5 );
In as3, 5 is converted to big-Endian, which is the network byte order. Therefore, if the protocol uses network byte order as an agreed integer, it is okay to directly call writeshort.
The same is true for readshort (). When the other end transmits a 16bits integer, readshort () will sort it from the network's own order (big-Endian) convert to host byte order (Intel + windows is little-Endian ).
2. Event: progressevent
When the network comes up with data, flash sends this event.
Each time the underlying layer receives some data, it triggers an event and the ApplicationProgramNo action is made, and no notification is sent. It is different from the select/wsaasyncselect mechanism on Windows.
The as socket should already have a buffer, which stores the received TCP stream data.
In this event handler function, break down the TCP stream, read the message block to bytearray, perform preprocessing, and distribute it to a specific logic handler.
If you have responded to all other events such as close and error, it will be okay.