As3 socket details

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.