Before the example I would like give you a brief about XML connections :
XML socket connections vs binary socket connections:
1. An XMLsocket lets create a server connection that remains open until explicitly closed.
2. No need to having to continually open new server connections.
3. No need to explicitly request for sending data.
The protocol used by the XMLSocket class are :
* 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.
Note : XMLSocket has no HTTP tunneling capability.
[xml]
<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application xmlns:fx=”http://ns.adobe.com/mxml/2009″
xmlns:s=”library://ns.adobe.com/flex/spark”
xmlns:mx=”library://ns.adobe.com/flex/mx”
>
<fx:Script>
<![CDATA[
import com.*;
import mx.controls.Alert;
private var _xmlSocket:XMLSocketClient
private function connectToServer(event:MouseEvent):void {
try{
trace(‘Client is trying to connect with server’)
_xmlSocket = new XMLSocketClient()
}
catch(err:Error){
Alert.show(‘error’+err.name);
}
}
private function sendData():void
{
_xmlSocket.send(msg_txt.text);
}
private function onDisconnectClicked():void
{
_xmlSocket.disconnect();
}
]]>
</fx:Script>
<s:Button x=”327″ y=”40″ label=”Disconnect” width=”95″ id=”disconnect_btn” click=”onDisconnectClicked()”/>
<s:Button x=”213″ y=”126″ label=”Send” width=”95″ id=”send_btn” click=”sendData()”/>
<s:TextInput x=”124″ y=”96″ width=”298″ id=”msg_txt” maxChars=”100″/>
<s:Button x=”183″ y=”74″ width=”125″ height=”41″ label=”Connect” click=”connectToServer(event)”/>
</s:Application>
[/xml]
Tags: binary socket, Flex XML socket connections, socket connection, socket connections, Socket server, stream socket, TCP/IP, TCP/IP stream socket, XML socket, XML socket connections, XML socket connections vs binary socket connections