U-X > XMLSocket (object) |
![]() ![]() ![]() |
XMLSocket (object)
The XMLSocket object implements client sockets that allow the computer running the Flash Player to communicate with a server computer identified by an IP address or domain name.
To use the XMLSocket object, the server computer must run a daemon that understands the protocol used by the XMLSocket object. The protocol is as follows:
![]() |
XML messages are sent over a full-duplex TCP/IP stream socket connection. |
![]() |
Each XML message is a complete XML document, terminated by a zero byte. |
![]() |
An unlimited number of XML messages can be sent and received over a single XMLSocket connection. |
The XMLSocket object is useful for client-server applications that require low latency, such as real-time chat systems. A traditional HTTP-based chat solution frequently polls the server and downloads new messages using an HTTP request. In contrast, an XMLSocket chat solution maintains an open connection to the server, which allows the server to immediately send incoming messages without a request from the client.
Setting up a server to communicate with the XMLSocket object can be challenging. If your application does not require real-time interactivity, use the loadVariables
action, or Flash HTTP-based XML server connectivity (XML.load
, XML.sendAndLoad
, XML.send
), instead of the XMLSocket object.
To use the methods of the XMLSocket object, you must first use the constructor, new XMLSocket
, to create a new XMLSocket object.
Because the XMLSocket object establishes and maintains an open connection to the server, the following restrictions have been placed on the XMLSocket object for security reasons:
![]() |
The |
![]() |
The |
Method Description Closes an open socket connection. Establishes a connection to the specified server. Sends an XML object to the server.
Method summary for the XMLSocket object
Method Description A callback function that is invoked when an XMLSocket connection is closed. A callback function that is invoked when an XMLSocket connection is established. A callback function that is invoked when an XML message has been downloaded from the server. A callback function that is invoked when an XML object arrives from the server.
Event handler summary for the XMLSocket object
Constructor for the XMLSocket object
Availability
Flash Player 5.
Usage
new XMLSocket()
Parameters
None.
Returns
Nothing.
Description
Constructor; creates a new XMLSocket object. The XMLSocket object is not initially connected to any server. You must call the XMLSocket.connect
method to connect the object to a server.
Example
myXMLSocket = new XMLSocket();
See also
![]() ![]() ![]() |