About XML 661
Using the XMLSocket class
ActionScript provides a built-in XMLSocket class, which lets you open a continuous
connection with a server. A socket connection lets the server publish, or push, information to
the client as soon as that information is available. Without a continuous connection, the
server must wait for an HTTP request. This open connection removes latency issues and is
commonly used for real-time applications such as chats. The data is sent over the socket
connection as one string and should be formatted as XML. You can use the XML class to
structure the data.
To create a socket connection, you must create a server-side application to wait for the socket
connection request and send a response to the SWF file. This type of server-side application
can be written in a programming language such as Java.
You can use the
connect() and send() methods of the XMLSocket class to transfer XML to
and from a server over a socket connection. The
connect() method establishes a socket
connection with a web server port. The
send() method passes an XML object to the server
specified in the socket connection.
When you invoke the
connect() method, Flash Player opens a TCP/IP connection to the
server and keeps that connection open until one of the following events happens:
■ The close() method of the XMLSocket class is called.
■ No more references to the XMLSocket object exist.
■ Flash Player exits.
■ The connection is broken (for example, the modem disconnects).
NOTE
The XMLSocket class cannot tunnel through firewalls automatically because, unlike the
Real-Time Messaging Protocol (RTMP), XMLSocket has no HTTP tunneling capability.
If you need to use HTTP tunneling, consider using Flash Remoting or Flash
Communication Server (which supports RTMP) instead.