Use XMLSocket to monitor the production system in flash (2-2)

Source: Internet
Author: User
Tags fully qualified domain name
2. skills 2. XMLSocket object implements the client socket, and promises to establish a socket connection with the server using a browser including Flash, flash can then send XML data to each other using the server and create a socket connection 2. skills first

2. XMLSocket object


The client socket is implemented, and the browser used by Flash is allowed to establish a socket connection with the server. then, Flash and the server can send XML data to each other. after a socket connection is established, there is no limit on the amount of data transmitted on the connection until the socket connection is closed.

When using XMLSocket objects, pay attention to the following two points:

O XML data sent on the socket connection. each piece of data is separated by 0 Bytes. for details, see the following service.
O Flash must use the same IP address or subdomain of the connected host with the corresponding Web server. The so-called the same domain name is in the same domain name space, for example, contains Flash to use the web page is downloaded from the mail.real-ok.com, the name.mail.real-ok.com is a sub-domain, agreed to establish a connection, while the real-ok.com is not a sub-domain, flash security rules do not allow connection establishment.

The process for applying the XMLSocket object is as follows:

1) create an XMLSocket object

MySocket = new XMLSocket ();

2) set the inherent XMLSocket object

MySocket. onConnect = myOnConnect;
MySocket. onData = myOnData;
MySocket. onXML = myOnXML;
MySocket. onClose = myOnClose;

In the preceding four statements, four event processing functions of mySocket are distinguished. myOnConnect, myOnData, and myOnXML are provided with a parameter function, and myOnClose does not contain a parameter, when an event is generated, the corresponding processing function is called.

3) apply the connect method of the XMLSocket object to establish a connection with the service mySocket. connect (null, 6666 );

The connect method has two parameters. The first parameter indicates the host to be connected. it can be a fully qualified domain name and the IP address of the user. Note that when an IP address is used, for example, 127.0.0.1 must be treated as a string, that is, the IP address should be enclosed in quotation marks. If it is null, the IP address that connects to the Web server (the Web page containing the current Flash used is downloaded from the Web server.

The second parameter indicates the port to be connected. because ports lower than 1024 are occupied by common programs, Flash security rules do not promise to establish a connection on ports lower than 1024. The connect method returns the Boolean variables true or false, indicating whether the connection is successful. For example:

If (! MySocket. connect (null, 2000 )){
MyTextField. text = "connection failed !";
}

In the preceding statement, if the connection fails and the connect method returns flase, the content of myTextField (an instance of a non-static text TextField object) is set to "connection failed !".

When the XMLSocket object is connected to the server, the onConnect event is triggered, and the corresponding event processing function (see the settings in step 2 above) is myOnConnect. the parameters in this function have the same meaning as the return values of the connect method, for details, see the following client instance.


Related Article

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.