?? connector.as
字號(hào):
package cn.humanmonth.chat{
import flash.events.DataEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.XMLSocket;
/**
*
* @author Piterlin
* 處理鏈接的細(xì)節(jié)
*/
public class Connector {
// private var domain:String="192.168.20.2";
private var domain:String="humanmonth.cn";
// private var domain:String="localhost";
private var socket:XMLSocket;
private var initEvent:Function;
private var onDataEvent:Function;
private var ioErrorEvent:Function;
private var httpIOErrorEvent:Function;
private var shouldSendKeepAlive:Boolean=false;
public function Connector(initEvent:Function,onDataEvent:Function,ioErrorEvent:Function,httpIOErrorEvent:Function) {
this.initEvent=initEvent;
this.onDataEvent=onDataEvent;
this.ioErrorEvent=ioErrorEvent;
this.httpIOErrorEvent=httpIOErrorEvent;
this.connect();
}
public function connect():void {
var loader:URLLoader=new URLLoader();
loader.addEventListener(IOErrorEvent.IO_ERROR,httpIOErrorEvent);
loader.addEventListener(Event.COMPLETE,onComplete);
loader.load(new URLRequest("http://"+domain+"/ChatServerServlet.do"));
}
private function onComplete(event:Event):void {
var loader:URLLoader=URLLoader(event.target);
var port:Number=loader.data;
socket=new XMLSocket() ;
socket.addEventListener(Event.CONNECT,initEvent);
socket.addEventListener(DataEvent.DATA,onDataEvent);
socket.addEventListener(IOErrorEvent.IO_ERROR,ioErrorEvent);
socket.connect(domain,port);
}
public function send(tag:String,value:String):void {
try {
this.setShouldSendKeepAliveFalse();
socket.send("<"+tag+">"+value+"</"+tag+">\r\n");
} catch (er:Error) {
this.ioErrorEvent(null);
}
}
public function setShouldSendKeepAliveFalse():void{
this.shouldSendKeepAlive=false;
}
public function getShouldSendKeepAlive():Boolean{
return this.shouldSendKeepAlive;
}
public function setShouldSendKeepAliveTrue():void{
this.shouldSendKeepAlive=true;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -