Xml代码
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"minWidth="955"minHeight="600">
private var socket:Socket = null;
protected function button1_clickHandler(event:MouseEvent):void
{
if(socket==null || !socket.connected){
//连接服务器(ip,port)
socket = new Socket("localhost",10086);
//成功连接状态事件
socket.addEventListener(Event.CONNECT,function connFun(e:Event):void{
l_status.text = "Connect to server success...";
});
//连接中断事件
socket.addEventListener(Event.CLOSE,function closeFun(e:Event):void{
l_status.text = "Connect to server closed...";
});
//连接异常事件
socket.addEventListener(IOErrorEvent.IO_ERROR,function closeFun(e:IOErrorE