网站首页
IC库存
IC展台
电子资讯
技术资料
PDF文档
我的博客
IC72论坛
ic72 logo
资料首页最新产品 技术参数 电路图 设计应用 解决方案 代理商查询 IC替换 IC厂商 电子辞典
关键字: 技术文章 PDF资料 IC价格 电路图 代理商查询 IC替换 IC厂商 电子辞典

FlashCom 连接器

本连接器代码是可支持Flashcom多端口(1935,443,80),多协议(rtmp,rtmps,rtmpt)扫描.
以下是Connector.as代码片段:
//======================================; 
// Name:Connector.as 
// Auther:Kinglong 
// Email:kinglong@gmail.com 
// Date:2005-06-29 
// Desc:FCS连接器; 
//=======================================; 
import mx.events.EventDispatcher; 
//=======================================; 
class com.klstudio.fcs.Connector extends Object{ 
 //======================================; 
 private var dispatchEvent:Function; 
 public var addEventListener:Function; 
 public var removeEventListener:Function; 
 public var target:Object; 
 public var index:Number; 
 //======================================; 
 private var __connectListArray:Array; 
 private var __host_name:String; 
 private var __app_name:String; 
 private var __connected:Boolean; 
 private var __connect_list_point:Number; 
 private var __connection_num:Number; 
 private var __connection_max_num:Number; 
 private var __connection:NetConnection; 
 private var __connection_params:Object; 
 //=======================================; 
 private var __mar_next_connect:Number; 
 private var __mar_all_failed_connect:Number; 
 //=======================================; 
 function Connector(host:String,app:String){ 
  if(arguments.length>1){ 
   this.__host_name = host; 
   this.__app_name = app; 
  } 
  this.initConnector(); 
 } 
 //========================================; 
 // 初始化对象; 
 //========================================; 
 private function initConnector():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 = new Array(); 
  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}); 
  //=======================================;   
 } 
 //========================================; 
 // 启动连接表; 
 //========================================; 
 private function doActualConnect():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; 
  var i:Number; 
  for(i=0;i<this.__connectListArray.length;i++){ 
   this["temp_nc_"+i] = new NetConnection(); 
   this["temp_nc_"+i].index = i; 
   this["temp_nc_"+i].target = this; 
   this["temp_nc_"+i].onStatus = this.doStatus; 
  } 
  var connection_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); 
 } 
 //========================================; 
 // 下一个连接; 
 //========================================; 
 private function nextConnect():Void{ 
  clearInterval(this.__mar_next_connect); 
  this.__connect_list_point ++; 
  if(this.__connect_list_point<this.__connectListArray.length){   
   var connection_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); 
  } 
 } 
 //=========================================; 
 // 下一个连接; 
 //=========================================; 
 private function allFailedConnect():Void{ 
  clearInterval(this.__mar_all_failed_connect); 
  this.doActualConnect(); 
 } 
 //=========================================; 
 // 取消所有线程; 
 //=========================================; 
 private function removeAllTimeOut(ncIndex:Number):Void{ 
  if(arguments.length == 0){ 
   ncIndex = -1; 
  } 
  clearInterval(this.__mar_next_connect); 
  clearInterval(this.__mar_all_failed_connect); 
  var i: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(); 
    delete this["temp_nc_"+i]; 
   } 
  } 
 } 
 //=========================================; 
 private function doStatus(ncInfo:Object):Void{ 
  this.target.onStatus(this.index,ncInfo); 
 } 
 //=========================================; 
 private function onStatus(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; 
  }   
 } 
 //=========================================; 
 // 调试; 
 //=========================================; 
 private function myTrace(msg:Object):Void{ 
  trace("#Connector#: "+msg); 
  getURL("FSCommand:log", "#Connector#: "+msg); 
 } 
 //=========================================; 
 // 设置连接参数; 
 //=========================================; 
 public function setConnectParams(param:Object):Void{ 
  this.__connection_params = param; 
 } 
 //=========================================; 
 // 设置连接表; 
 //=========================================; 
 public function setConnectListArray(arr:Array):Void{ 
  this.__connectListArray = arr; 
 } 
 //=========================================; 
 // 设置最大尝试连接资料; 
 //=========================================; 
 public function setConnectMaxNum(num:Number):Void{ 
  if(num>1 && num <11){ 
   this.__connection_max_num = num; 
  } 
 } 
 //=========================================; 
 // 连接FCS服务器; 
 //=========================================; 
 public function connect():Void{ 
  if(this.__connected) return; 
  this.__connection_num = 0; 
  this.doActualConnect(); 
 } 
 //=========================================; 
 // 检查是否连接成功; 
 //=========================================; 
 public function isConnected():Boolean{ 
  return this.__connected;  
 } 
 //=========================================; 
 // 获取主连接NC; 
 //=========================================; 
 public function getConnection():NetConnection{ 
  return this.__connection;  
 }  
热门搜索:2838319 ADC128S102CIMTX PS120406 BQ25895MRTWR TLP604 IS-1000 2839237 01M1001JF TLP712B SS480806 2320296 ADC128S102CIMTX 2839240 EURO-4 TLM626SA PS-415-HGULTRA 2838228 PS361220 PS240406 TLP606B SBB8006-SS-1 TLM825GF 02B5000JF 02M1001JF 2920120
COPYRIGHT:(1998-2010) IC72 达普IC芯片交易网
客户服务:service@IC72.com 库存上载:IC72@IC72.com
(北京)联系方式: 在线QQ咨询:点击这里给我发消息 联系电话:010-82614113 传真:010-82614123
京ICP备06008810号-21 京公网安备 11010802032910 号 企业资质