分享
 
 
 

FlashCom连接器

王朝other·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

本连接器代码是可支持Flashcom多端口(1935,443,80),多协议(rtmp,rtmps,rtmpt)扫描.

以下是Connector.as代码片段:

//======================================;

//Name:Connector.as

//Auther:Kinglong

//Email:kinglong@gmail.com

//Date:2005-06-29

//Desc:FCS连接器;

//=======================================;

importmx.events.EventDispatcher;

//=======================================;

classcom.klstudio.fcs.ConnectorextendsObject{

//======================================;

privatevardispatchEvent:Function;

publicvaraddEventListener:Function;

publicvarremoveEventListener:Function;

publicvartarget:Object;

publicvarindex:Number;

//======================================;

privatevar__connectListArray:Array;

privatevar__host_name:String;

privatevar__app_name:String;

privatevar__connected:Boolean;

privatevar__connect_list_point:Number;

privatevar__connection_num:Number;

privatevar__connection_max_num:Number;

privatevar__connection:NetConnection;

privatevar__connection_params:Object;

//=======================================;

privatevar__mar_next_connect:Number;

privatevar__mar_all_failed_connect:Number;

//=======================================;

functionConnector(host:String,app:String){

if(arguments.length>1){

this.__host_name=host;

this.__app_name=app;

}

this.initConnector();

}

//========================================;

//初始化对象;

//========================================;

privatefunctioninitConnector():Void{

//=======================================;

EventDispatcher.initialize(this);

//=======================================;

this.__connected=false;

this.__connection_num=0;

this.__connection_max_num=3;

this.__connection=null;

this.__connection_params=null;

//=======================================;

this.__connectListArray=newArray();

this.__connectListArray.push({protocol:"rtmp",port:1935});

this.__connectListArray.push({protocol:"rtmp",port:443});

this.__connectListArray.push({protocol:"rtmpt",port:80});

this.__connectListArray.push({protocol:"rtmps",port:443});

//=======================================;

}

//========================================;

//启动连接表;

//========================================;

privatefunctiondoActualConnect():Void{

this.removeAllTimeOut();

this.__connection_num++;

if(this.__connection_num>this.__connection_max_num){

this.myTrace("总共尝试"+this.__connection_max_num+"次都失败!");

this.dispatchEvent({type:"failed",data:"服务器连接失败!"});

return;

}

this.__connect_list_point=0;

vari:Number;

for(i=0;i<this.__connectListArray.length;i++){

this["temp_nc_"+i]=newNetConnection();

this["temp_nc_"+i].index=i;

this["temp_nc_"+i].target=this;

this["temp_nc_"+i].onStatus=this.doStatus;

}

varconnection_uri:String=this.__connectListArray[this.__connect_list_point].protocol+"://"+this.__host_name+":"+this.__connectListArray[this.__connect_list_point].port+"/"+this.__app_name;

this.myTrace("[尝试"+this.__connection_num+"/"+this.__connection_max_num+"]连接到"+(this.__connect_list_point+1)+"/"+this.__connectListArray.length+":"+connection_uri);

this.dispatchEvent({type:"connect",data:this.__connectListArray[this.__connect_list_point]});

this["temp_nc_"+this.__connect_list_point].connect(connection_uri,this.__connection_params);

this.__mar_next_connect=setInterval(this,"nextConnect",3000);

}

//========================================;

//下一个连接;

//========================================;

privatefunctionnextConnect():Void{

clearInterval(this.__mar_next_connect);

this.__connect_list_point++;

if(this.__connect_list_point<this.__connectListArray.length){

varconnection_uri:String=this.__connectListArray[this.__connect_list_point].protocol+"://"+this.__host_name+":"+this.__connectListArray[this.__connect_list_point].port+"/"+this.__app_name;

this.myTrace("[尝试"+this.__connection_num+"/"+this.__connection_max_num+"]连接到"+(this.__connect_list_point+1)+"/"+this.__connectListArray.length+":"+connection_uri);

this.dispatchEvent({type:"connect",data:this.__connectListArray[this.__connect_list_point]});

this["temp_nc_"+this.__connect_list_point].connect(connection_uri,this.__connection_params);

this.__mar_next_connect=setInterval(this,"nextConnect",3000);

}

}

//=========================================;

//下一个连接;

//=========================================;

privatefunctionallFailedConnect():Void{

clearInterval(this.__mar_all_failed_connect);

this.doActualConnect();

}

//=========================================;

//取消所有线程;

//=========================================;

privatefunctionremoveAllTimeOut(ncIndex:Number):Void{

if(arguments.length==0){

ncIndex=-1;

}

clearInterval(this.__mar_next_connect);

clearInterval(this.__mar_all_failed_connect);

vari:Number;

for(i=0;i<this.__connectListArray.length;i++){

if(i==ncIndex){

this.myTrace(this.__connectListArray[ncIndex].protocol+"://"+this.__host_name+":"+this.__connectListArray[ncIndex].port+"/"+this.__app_name+"连接尝试成功!");

}else{

this["temp_nc_"+i].close();

deletethis["temp_nc_"+i];

}

}

}

//=========================================;

privatefunctiondoStatus(ncInfo:Object):Void{

this.target.onStatus(this.index,ncInfo);

}

//=========================================;

privatefunctiononStatus(ncIndex:Number,ncInfo:Object):Void{

switch(ncInfo.code){

case"NetConnection.Connect.Success":

this.removeAllTimeOut(ncIndex);

this.__connection=this["temp_nc_"+ncIndex];

this.__connected=true;

this.dispatchEvent({type:"success"});

break;

case"NetConnection.Connect.Failed":

this.myTrace(this.__connectListArray[ncIndex].protocol+"://"+this.__host_name+":"+this.__connectListArray[ncIndex].port+"/"+this.__app_name+"连接尝试失败!");

if(ncIndex==this.__connectListArray.length-1){

this.myTrace("所有连接尝试失败!");

this.removeAllTimeOut();

this.__mar_all_failed_connect=setInterval(this,"allFailedConnect",5000);

}

break;

case"NetConnection.Connect.Closed":

case"NetConnection.Connect.AppShutdown":

this.dispatchEvent({type:"closed"});

break;

case"NetConnection.Connect.Rejected":

this.removeAllTimeOut();

this.myTrace("FlashCom服务器不接收连接尝试!");

this.dispatchEvent({type:"failed",data:ncInfo.application.message});

break;

}

}

//=========================================;

//调试;

//=========================================;

privatefunctionmyTrace(msg:Object):Void{

trace("#Connector#:"+msg);

getURL("FSCommand:log","#Connector#:"+msg);

}

//=========================================;

//设置连接参数;

//=========================================;

publicfunctionsetConnectParams(param:Object):Void{

this.__connection_params=param;

}

//=========================================;

//设置连接表;

//=========================================;

publicfunctionsetConnectListArray(arr:Array):Void{

this.__connectListArray=arr;

}

//=========================================;

//设置最大尝试连接资料;

//=========================================;

publicfunctionsetConnectMaxNum(num:Number):Void{

if(num>1&&num<11){

this.__connection_max_num=num;

}

}

//=========================================;

//连接FCS服务器;

//=========================================;

publicfunctionconnect():Void{

if(this.__connected)return;

this.__connection_num=0;

this.doActualConnect();

}

//=========================================;

//检查是否连接成功;

//=========================================;

publicfunctionisConnected():Boolean{

returnthis.__connected;

}

//=========================================;

//获取主连接NC;

//=========================================;

publicfunctiongetConnection():NetConnection{

returnthis.__connection;

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有