keepalivedaemon.as

来自「flex实现的前台」· AS 代码 · 共 35 行

AS
35
字号
package cn.humanmonth.chat.daemon
{
	import cn.humanmonth.chat.Connector;
	import cn.humanmonth.chat.Protocol;
	
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	/**
	 * @author Piterlin
	 * 每隔六十秒检查一次Connector的保活标志位,看是否需要发送保活信息
	 */
	public class KeepAliveDaemon
	{
		private var protocol:Protocol;
		private var connector:Connector;
		private var timer:Timer;
		public function KeepAliveDaemon(protocol:Protocol,connector:Connector)
		{
			this.protocol=protocol;
			this.connector=connector;
			timer=new Timer(60000,0);
			timer.addEventListener(TimerEvent.TIMER,timerHandler);
			timer.start();
		}

		public function timerHandler(event:TimerEvent):void{
		if(connector.getShouldSendKeepAlive()){
		protocol.sendKeepAliveSignal();
		}else{
		connector.setShouldSendKeepAliveTrue();
		}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?