Previously there was another article, but I accidentally wiped it. I apologize to those who came to this page in the hope of finding here information on the jQuery Dialog. Although, if the copy is not preserved in the network ... So the article was so-so :)I want to offer everyone to my translation of the document from the official documentation for
Adobe Flex 3 - Socket connections (Socket connections)
The second part here is
Flex3. Socket connections Part 2Socket connections
There are two types of socket connections available in Action Script 3.0: XML socket connections (XML Sockets) and binary (binary) socket connections. XML socket allows you to connect to a remote server and create a connection that will remain open until it is explicitly closed
(in a word, it simulates a permanent connection to the server) . This allows you to transfer XML data between the server and the client, without the need to constantly open a new connection. Another advantage of using a server based on XML sockets is that the user does not need to constantly send requests to receive data from the server. To transfer data from the server, you do not need to wait for a request from the client, and you can immediately send the data to each client connected to the server.
')
Binary sockets are somewhat similar to XML sockets, and differ only in the fact that they do not use special XML packages for data exchange between the client and the server. Instead, the data is transmitted in binary (binary) form.
Class socket
Introduced in ActionScript 3.0, the Socket class allows you to create a socket connection to read and write raw binary data.
It is similar to the XMLSocket class, but does not allow you to specify the format of the received and transmitted data. Class socket
useful when interacting with servers that use binary (binary) protocols. Using binary sockets connections, you can write code that allows you to communicate over various Internet protocols, such as POP3, SMTP, IMAP, and NNTP. And, this will allow Flash Player to connect to mail and news servers.
The Socket class inherits all the methods described in the IDataInput and IDataOutput interfaces (located in the flash.utils package), these methods are used to read and write from the socket.XMLSocket class
ActionScript contains the built-in class XMLSocket, which allows you to create a continuous connection with the server. This type of connection eliminates the delay arising from the constant polling of the server and is mainly used in real-time applications such as chat or multiplayer games.
The basis of the traditional implementation of HTTP-based chat, is the constant polling of the server with a certain frequency and downloading new messages using an HTTP request. In contrast to the traditional solution, chat based on an XML socket, it maintains a permanent open connection and allows the server to immediately send incoming messages without waiting for a request from a client.
To create a socket connection, you need to create a server application (server, in one word) that will wait for a connection request and return the SWF response to the application (file). A server application of this type can be written using programming languages such as Java, Python or Perl. To use the XMLSocket class, on the server side (server computer) you need to start a daemon (a
program running in the background ) that understands the protocol that XMLSocket uses.
Requirements for the protocol:- XML messages are sent during the full duplex TCP / IP stream socket connection.
- Each XML message must be a full-fledged XML document, and terminated with a null byte.
- Within one socket connection, XML can be received and sent an unlimited number of XML messages.
Note: The XMLSocket class cannot automatically tunnel through a firewall because, unlike the Real-Time Messaging Protocol (RTMP), the XML socket does not support HTTP tunneling. If you need HTTP tunneling, instead of XMLSocket, you can use Flash Remoting and Flash Media Server (which support RTMP) as an option.
Possible limitations when using XMLSocket when connecting to a server:
- XMLSocket.connect () can only connect to a TCP port with a number greater than or equal to 1024. One of the consequences of this restriction is that the daemons running on the server and that interact with the XMLSocket object must also have a port number greater than or equal to 1024. Ports with Numbers below 1024 are used by the system, for services such as FTP (21), Telnet (23), SMTP (25), HTTP (80) and POP3 (110), XMLSocket is prohibited from using these port numbers for security reasons. Limiting the port number reduces the possibility of unauthorized access to these resources.