XMLSocket class

Availability

Flash Player 5.

Description

The XMLSocket class implements client sockets that allow the computer running Flash Player to communicate with a server computer identified by an IP address or domain name. The XMLSocket class 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.

To use the XMLSocket class, the server computer must run a daemon that understands the protocol used by the XMLSocket class. The protocol is as follows:

The following restrictions apply to how and where an XMLSocket object can connect to the server:

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 class.

To use the methods of the XMLSocket class, you must first use the constructor, new XMLSocket, to create a new XMLSocket object.

Method summary for the XMLSocket class

Method

Description

XMLSocket.close()

Closes an open socket connection.

XMLSocket.connect()

Establishes a connection to the specified server.

XMLSocket.send()

Sends an XML object to the server.

Event handler summary for the XMLSocket class

Event handler

Description

XMLSocket.onClose()

An event handler that is invoked when an XMLSocket connection is closed.

XMLSocket.onConnect()

An event handler that is invoked by Flash Player when a connection request initiated through XMLSocket.connect() has succeeded or failed.

XMLSocket.onData()

An event handler that is invoked when an XML message has been downloaded from the server.

XMLSocket.onXML()

An event handler that is invoked when an XML object arrives from the server.

Constructor for the XMLSocket class

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 XMLSocket.connect() to connect the object to a server.