FMS广播(broadcastMsg)

最近在写一个RIA系统,要实现广播消息,想用broadcastMsg来解决,结果发现fms官方文档的实际有点问题,所以就把我写的东西贴出来,希望对读者有帮助。

客户端代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:Script>
  <![CDATA[
   import mx.controls.Alert;
   private var cam:Camera;
   private var mic:Microphone;
   private var cn:NetConnection;
   private var ns:NetStream;
   private var conStr:String="rtmp://192.168.1.188/AvFashion"
   private var userName:String;
   private var cnResponder:Responder=new Responder(onReply);
   private function getConnection():void
   {
    userName=user.text;
    cn=new NetConnection();
    cn.client=new Object();

    cn.client.sbmsg=function(msf:String):void{Alert.show(msf);};
    cn.connect(conStr,userName);
    
    cn.addEventListener(NetStatusEvent.NET_STATUS,netConnetHanndler);
    //cn.client=this;
    cn.call("msgFromSrv",cnResponder,"中国");
   }
   private function setVideo():void
   {
    cam=Camera.getCamera();
    
   }
   private function netConnetHanndler(msg:NetStatusEvent):void
   {
    if(msg.info.code == "NetConnection.Connect.Success")
       {
         Alert.show("连接成功");
       }
       else
       {
         Alert.show("连接失败");
       }
   }
   
   private function onReply(result:String):void
   {
    msg.text=result;
   }
   
   ]]>
 </mx:Script>
 <mx:VideoDisplay x="170" y="38" width="298" height="224"/>
 <mx:Label x="170" y="280" text="UerName:" />
 <mx:Button x="359" y="278" label="Get Connecton" id="GetConnection" click="getConnection()"/>
 <mx:TextArea x="170" y="315" width="298" id="msg"/>
 <mx:TextInput x="239" y="278" width="102" id="user"/>
  

</mx:Application>

服务端代码:

//定义用户的列表
userList=[];
application.onAppStart=function()
{
 trace("fms set up server......");
 trace("magictanghehe.......");
}
application.onConnect = function(currentClient,username)

 
 application.acceptConnection(currentClient);
 currentClient.username = username;
 userList.push(username);
 
 currentClient.msgFromSrv= function(value)
 {
               
    return "Welcome to: "+currentClient.username+" for bring "+value.toString();;

 }
  application.broadcastMsg("sbmsg", "Hello World");
 trace("当前用户列表"+userList);
}

 

fms3,flex3上调试通过。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值