User Guide
Socket connections 387
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, Python, or Perl. To use the
XMLSocket class, the server computer must run a daemon that understands the protocol used
by the XMLSocket class. The protocol is described in the following list:
■ 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 (0) byte.
■ An unlimited number of XML messages can be sent and received over a single
XMLSocket connection.
The following restrictions apply to how and where an XMLSocket object can connect to the
server:
■ The XMLSocket.connect() method can connect only to TCP port numbers greater than
or equal to 1024. One consequence of this restriction is that the server daemons that
communicate with the
XMLSocket object must also be assigned to port numbers greater
than or equal to 1024. Port numbers below 1024 are often used by system services such as
FTP (21), Telnet (23), SMTP (25), HTTP (80), and POP3 (110), so XMLSocket objects
are barred from these ports for security reasons. The port number restriction limits the
possibility that these resources will be inappropriately accessed and abused.
■ The XMLSocket.connect() method can connect only to computers in the same domain
where the SWF file resides. This restriction does not apply to SWF files running off a local
disk. (This restriction is identical to the security rules for
URLLoader.load().) To
connect to a server daemon running in a domain other than the one where the SWF
resides, you can create a security policy file on the server that allows access from specific
domains.
You can use the
XMLSocket.connect() and XMLSocket.send() methods of the XMLSocket
class to transfer XML to and from a server over a socket connection. The
XMLSocket.connect() method establishes a socket connection with a web server port. The
XMLSocket.send() method passes an XML object to the server specified in the socket
connection.
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 Media
Server (which supports RTMP) instead.
NOTE
Setting up a server to communicate with the XMLSocket object can be challenging. If
your application does not require real-time interactivity, use the URLLoader class
instead of the XMLSocket class.