- 浏览: 1428735 次
- 性别:
- 来自: 苏州
文章分类
- 全部博客 (564)
- 算法 (7)
- 流金岁月 (1)
- Javascript (30)
- actionscript (108)
- as3.0 game (14)
- flex (84)
- fms2 (27)
- 正则表达式 (7)
- 开源组件代码(as3.0) (1)
- Pv3d (13)
- Cairngorm (4)
- vbs (54)
- VB程序设计 (26)
- 计算机应用与维护 (4)
- 职场实用穿衣技巧 (3)
- 历史风云 (15)
- 淡泊明志,宁静致远 (12)
- 情感 (26)
- 杂谈 (41)
- 越南风 (14)
- DirectX (9)
- Dev-cpp (11)
- 回望百年 (2)
- 建站经验 (2)
- Python (24)
- 网络赚钱 (4)
- php (2)
- html (1)
- ob0短址网 (1)
- ob0.cn (1)
- wordpress (1)
- pandas logistic (1)
- haxe (1)
- opencv (1)
- 微信小程序 (3)
- vue (3)
- Flutter (1)
最新评论
-
GGGGeek:
第一个函数滚动监听不起作用,onPageScroll可以
微信小程序--搜索框滚动到顶部时悬浮 -
naomibyron:
解决办法:工具 -> 编译选项 -> 编译器 ...
dev-c++中编译含WINSOCK的代码出现错误的解决方法 -
haichuan11:
这个…… 代码不全真的是让人很憋屈的感觉啊
actionScript 3.0 图片裁剪及旋转 -
chenyw101:
老兄能留个QQ号吗?具体的我有些东西想请教下你
用VB制作网站登陆器 -
yantao1943:
貌似有点问题,只派发一次事件啊
使用ActionScript 2.0或ActionScript 3.0处理音频文件的提示点(cue
今天写了下简易聊天室的加强版 , 其实功能也十分有很 , 不过比前面提到的简易聊天室要智能了许多 , 这个聊天室的主要功能有以下 :
<!---->1. <!---->同一用户不能重复登陆 , 否则服务端拒绝 ;
<!---->2. <!---->可以得到聊天室里人员的列表 ;
<!---->3. <!---->新用户上线提示 ;
<!---->4. <!---->用户离线提示 ;
<!---->5. <!---->发送文本消息 ;
<!---->6. <!---->新用户上线 , 更新所有聊天室成员列表名单 ;
<!---->7. <!---->用户离线 , 更新所有聊天室成员列表名单 ;
技术上并没有什么花样儿 , 还是如下几个 :
<!---->1. <!---->客户端与服务端的建立连接 ;
<!---->2. <!---->监听连接状态 ;
<!---->3. <!---->客户端调用服务端函数 ;
<!---->4. <!---->服务端调用客户端函数
先看看粗糙的效果图:
再看看代码吧:
先看客户端的:
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:com="com.*" backgroundColor="white">
- <mx:Style source="css.css"></mx:Style>
- <mx:Script>
- <![CDATA[
- import com.client.clientInvockObj;
- import mx.controls.TextInput;
- import com.carlcalderon.arthropod.Debug;
- import mx.utils.StringUtil;
- public var nc:NetConnection;
- private static const RTMP_URL:String="rtmp://localhost/chatinglist";
- public var loginName:String;
- private var isConnectSuccess:Boolean;
- private function initApp():void{
- nc=new NetConnection();
- nc.connect(RTMP_URL,loginName);
- nc.addEventListener(NetStatusEvent.NET_STATUS,checkStatus);
- var obj:clientInvockObj=new clientInvockObj(chatList,chatContent);
- nc.client=obj;
- }
- private function checkStatus(e:NetStatusEvent):void{
- trace(e.info.code);
- Debug.log(e.info.code,Debug.BLUE);
- isConnectSuccess=(e.info.code=="NetConnection.Connect.Success");
- if(isConnectSuccess){
- nc.call("getMsg",new Responder(getMsgResult,getMsgFault));
- loginBtn.enabled=false;
- sendBtn.enabled=true;
- Debug.log("client connect success!");
- }
- }
- private function getMsgResult(chatMsgArray:Array):void{
- Debug.log("callBack:");
- for(var i:uint=0;i<chatMsgArray.length;i++){
- chatContent.text+=chatMsgArray[i]+"\n";
- }
- }
- private function getMsgFault():void{
- }
- public function sendLogin():void{
- if(StringUtil.trim(userName.text).length>0){
- loginName=userName.text;
- initApp();
- }
- }
- public function sendMessage():void{
- nc.call("sendMsg",null,loginName,msg.text);
- msg.text="";
- }
- ]]>
- </mx:Script>
- <mx:HBox width="100%">
- <mx:VBox width="200" height="100%">
- <mx:Label text="用户列表:"/>
- <mx:List id="chatList" width="200" height="400" labelField="userName" cornerRadius="7"/>
- </mx:VBox>
- <mx:VBox width="100%">
- <mx:HBox id="loginPanel" width="100%" height="100%">
- <mx:TextInput id="userName"/>
- <mx:Button label="登陆" id="loginBtn" click="sendLogin();"/>
- </mx:HBox>
- <mx:TextArea id="chatContent" width="250" height="400"/>
- <mx:HBox width="100%" height="100%">
- <mx:TextInput id="msg"/>
- <mx:Button label="发送消息" id="sendBtn" click="sendMessage();" enabled="false"/>
- </mx:HBox>
- </mx:VBox>
- <mx:VBox>
- </mx:VBox>
- </mx:HBox>
- </mx:Application>
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:com="com.*" backgroundColor="white"> <mx:Style source="css.css"></mx:Style> <mx:Script> <![CDATA[ import com.client.clientInvockObj; import mx.controls.TextInput; import com.carlcalderon.arthropod.Debug; import mx.utils.StringUtil; public var nc:NetConnection; private static const RTMP_URL:String="rtmp://localhost/chatinglist"; public var loginName:String; private var isConnectSuccess:Boolean; private function initApp():void{ nc=new NetConnection(); nc.connect(RTMP_URL,loginName); nc.addEventListener(NetStatusEvent.NET_STATUS,checkStatus); var obj:clientInvockObj=new clientInvockObj(chatList,chatContent); nc.client=obj; } private function checkStatus(e:NetStatusEvent):void{ trace(e.info.code); Debug.log(e.info.code,Debug.BLUE); isConnectSuccess=(e.info.code=="NetConnection.Connect.Success"); if(isConnectSuccess){ nc.call("getMsg",new Responder(getMsgResult,getMsgFault)); loginBtn.enabled=false; sendBtn.enabled=true; Debug.log("client connect success!"); } } private function getMsgResult(chatMsgArray:Array):void{ Debug.log("callBack:"); for(var i:uint=0;i<chatMsgArray.length;i++){ chatContent.text+=chatMsgArray[i]+"\n"; } } private function getMsgFault():void{ } public function sendLogin():void{ if(StringUtil.trim(userName.text).length>0){ loginName=userName.text; initApp(); } } public function sendMessage():void{ nc.call("sendMsg",null,loginName,msg.text); msg.text=""; } ]]> </mx:Script> <mx:HBox width="100%"> <mx:VBox width="200" height="100%"> <mx:Label text="用户列表:"/> <mx:List id="chatList" width="200" height="400" labelField="userName" cornerRadius="7"/> </mx:VBox> <mx:VBox width="100%"> <mx:HBox id="loginPanel" width="100%" height="100%"> <mx:TextInput id="userName"/> <mx:Button label="登陆" id="loginBtn" click="sendLogin();"/> </mx:HBox> <mx:TextArea id="chatContent" width="250" height="400"/> <mx:HBox width="100%" height="100%"> <mx:TextInput id="msg"/> <mx:Button label="发送消息" id="sendBtn" click="sendMessage();" enabled="false"/> </mx:HBox> </mx:VBox> <mx:VBox> </mx:VBox> </mx:HBox> </mx:Application>
还有一个用于绑定到客户端NetConnection的client类,供FMS调用:
- package com.client
- {
- import mx.controls.List;
- import mx.controls.TextArea;
- public class clientInvockObj
- {
- private var chatList:List;
- private var chatContent:TextArea;
- public function clientInvockObj(list:List,chatContent:TextArea)
- {
- this.chatList=list;
- this.chatContent=chatContent;
- }
- public function getUserList(userList:Array):void{
- chatList.dataProvider=userList;
- }
- public function getMsgInfo(msg:String):void{
- chatContent.text+=msg+"\n";
- }
- }
- }
package com.client { import mx.controls.List; import mx.controls.TextArea; public class clientInvockObj { private var chatList:List; private var chatContent:TextArea; public function clientInvockObj(list:List,chatContent:TextArea) { this.chatList=list; this.chatContent=chatContent; } public function getUserList(userList:Array):void{ chatList.dataProvider=userList; } public function getMsgInfo(msg:String):void{ chatContent.text+=msg+"\n"; } } }
下面是FMS服务端的:
- application.onAppStart=function(){
- trace("App started");
- this.chatMsgArray=new Array();
- this.userListArray=new Array();
- }
- application.onConnect=function(client,userName){
- trace(" try connect ")
- if(checkOnline(userName)){
- this.rejectConnection(client);
- return;
- }
- this.acceptConnection(client);
- trace("connected");
- client.userName=userName;
- trace(userName);
- application.userListArray.push(userName);
- sendUserList();
- sendMsgToClient("欢迎 "+userName+"进入聊天室.");
- client.getMsg=function(){
- trace("response client");
- return application.chatMsgArray;
- }
- client.sendMsg=function(loginUser,msg){
- trace("ClientName:"+loginUser);
- var chatInfo=loginUser+"--说:"+msg+"\n";
- application.chatMsgArray.push(chatInfo);
- sendMsgToClient(chatInfo);
- }
- }
- application.onDisconnect=function(client){
- trace("用户:"+client.userName+"----下线.");
- removeLeftUser(client.userName);
- sendUserList();
- sendMsgToClient("用户:"+client.userName+"----下线.");
- }
- function removeLeftUser(userName){
- for(var i=0;i<application.userListArray.length;i++){
- if(application.userListArray[i]==userName){
- application.userListArray.splice(i,1);
- }
- }
- }
- function sendMsgToClient(chatInfo){
- var leng=application.clients.length;
- for(var i=0;i<leng;i++){
- application.clients[i].call("getMsgInfo",null,chatInfo);
- }
- }
- function sendUserList(){
- var leng=application.clients.length;
- trace("client num:"+leng);
- for(var i=0;i<leng;i++){
- trace("getUserList----"+i);
- application.clients[i].call("getUserList",null,application.userListArray);
- }
- }
- function checkOnline(userName){
- var len=application.userListArray.length;
- for(var i=0;i<len;i++){
- if(application.userListArray[i]==userName){
- return true;
- }
- }
- return false;
- }
application.onAppStart=function(){ trace("App started"); this.chatMsgArray=new Array(); this.userListArray=new Array(); } application.onConnect=function(client,userName){ trace(" try connect ") if(checkOnline(userName)){ this.rejectConnection(client); return; } this.acceptConnection(client); trace("connected"); client.userName=userName; trace(userName); application.userListArray.push(userName); sendUserList(); sendMsgToClient("欢迎 "+userName+"进入聊天室."); client.getMsg=function(){ trace("response client"); return application.chatMsgArray; } client.sendMsg=function(loginUser,msg){ trace("ClientName:"+loginUser); var chatInfo=loginUser+"--说:"+msg+"\n"; application.chatMsgArray.push(chatInfo); sendMsgToClient(chatInfo); } } application.onDisconnect=function(client){ trace("用户:"+client.userName+"----下线."); removeLeftUser(client.userName); sendUserList(); sendMsgToClient("用户:"+client.userName+"----下线."); } function removeLeftUser(userName){ for(var i=0;i<application.userListArray.length;i++){ if(application.userListArray[i]==userName){ application.userListArray.splice(i,1); } } } function sendMsgToClient(chatInfo){ var leng=application.clients.length; for(var i=0;i<leng;i++){ application.clients[i].call("getMsgInfo",null,chatInfo); } } function sendUserList(){ var leng=application.clients.length; trace("client num:"+leng); for(var i=0;i<leng;i++){ trace("getUserList----"+i); application.clients[i].call("getUserList",null,application.userListArray); } } function checkOnline(userName){ var len=application.userListArray.length; for(var i=0;i<len;i++){ if(application.userListArray[i]==userName){ return true; } } return false; }
对不住大家,代码都没有写注释,因为跟我前面的那篇几乎一样,所以大家不明白可以参看前面的那篇.
发表评论
-
控制连接数量和密码保护-flashcom教程 密码保护
2008-10-30 14:03 1201学习flashcom+学习英语(烂到死),无任何目的,本篇仅 ... -
AMF3 + AS 3.0 + ASP.NET 完整配置过程及源文件
2008-09-11 16:04 3532AMF3 + AS 3.0 + ASP.NET 完整配置过程及 ... -
FLEX结合FMS制作在线视频认证
2008-09-09 14:24 3783很多交友网站都具体在线视频认证能,如51.com。参考它的认 ... -
flex 3 + .net开发flash Remoting四[完整代码
2008-08-28 16:11 2172一. 相关说明: 本篇将呈现完整的Flash Remot ... -
FMS Client AS 自訂類別物件傳遞
2008-08-27 15:04 1022透過與 FMS 連線,可以共享 SharedObject 物件 ... -
FMS 常常会用到 3个Call 和3个Send
2008-08-27 14:51 2172FMS 常常会用到 3个Call 和3个Send 关于Flas ... -
flex as3 fms相关的资料(转)
2008-08-27 14:36 1660FMS.rar FMS系列教程http://www.fs2 ... -
视频类
2008-08-27 09:21 1786Flash Player作为流媒体的表现形式之一,视频编码是其 ... -
一步一步学Flash Media Server
2008-08-26 18:03 4323从今天起,我们来学习一下 Flash Media Server ... -
再说说onSync,SharedObject
2008-08-26 16:44 1574* 最多人不懂的就是:那个list参数看代码: my_rso ... -
视频监控软件(2)---异步录像
2008-08-26 16:10 1341不好意思,让大家久等了!今天我要实现的一个功能是异步录像!先讲 ... -
视频监控软件(1)---FMS视频流共享
2008-08-26 16:07 2671呵呵!临近毕业了,本人选择的毕业设计题目是(基于B/S模式的 ... -
flash fms WebService 交互过程
2008-08-26 16:01 1686//flash客户端call服务器端的方法,服务器端调用WS的 ... -
游戏开发常用FMS类
2008-08-26 15:51 1416游戏开发常用FMS类 ... -
FLEX提高篇--------ShareObject对象详解
2008-08-26 14:23 1101ShareObject,顾名思义共享对象,而通常意义上的共享, ... -
客户端呼叫Flash Medis Server3服务端入门
2008-08-26 14:02 1422当你不仅仅只想用FLEX来做纯业务数据的管理时,或者当你的项目 ... -
FMS两种方式实现简易聊天室
2008-08-26 14:01 1641原理和代码都很简单,没什么好说的. 一:利用ShareOb ... -
Flex连接FMS实现用户列表(使用SharedObject)
2008-08-26 13:33 39561.先在FMS的安装目录中添加自己的应用(例如我的目录D:\M ... -
FMS 教程(SharedObject)用户列表
2008-08-26 13:32 2892FMS实现用户列表,一般都是利用List组件,和SharedO ... -
Fms教程7 理解共享对象
2008-08-26 13:13 1881理解共享对象 共享对象 ...
相关推荐
FMS+FLEX-----使用远程共享对象实现多人实时在线聊天 说明:这是我在网上看到的,收集并整理了一下。 因为我的积分不多了,所以虽然不是原创,但还是要一点资源分的。大家见谅。 压缩包中有说明文档和源码。说明...
FMS聊天室FMS聊天室FMS聊天室FMS聊天室FMS聊天室
利用flex和FMS建立聊天室,fms为源码
Flex+FMS写的视频聊天,在本机亲测通过。但唯一不足得是在别的机子上连接不成功。我也不知道为什么。望有才之士能完善。huzhaohui1992@qq.com 如能完善,请给我邮箱一份,在下感激不尽。
简易聊天室 flash多人聊天 FMS实现
By:闪闪威廉@nju中文版流媒体服务器---fms3教程。
Flex和Fms3打造在线聊天室(利用NetConnection对象和SharedObject对象) 中文说明文档和代码, 简单明了好资料
asp+fms语音聊天室asp+fms语音聊天室
FMS-Comp-373---Object-Wiring-Using-Spring-源码.rar
FMS制作聊天室例子,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
flash+fms2视频聊天室-附带源码 源码在 html页面上有下载的超链接
python库。 资源全名:mypy-boto3-fms-1.14.54.1.tar.gz
python库。 资源全名:mypy-boto3-fms-1.10.42.1.tar.gz
python库。 资源全名:mypy-boto3-fms-1.16.9.0.tar.gz
SAP-FMS快速指南
资源来自pypi官网。 资源全名:mypy-boto3-fms-1.18.50.tar.gz
资源来自pypi官网。 资源全名:mypy-boto3-fms-1.14.8.0.tar.gz
资源来自pypi官网。 资源全名:mypy-boto3-fms-1.11.11.0.tar.gz
免费美女视频聊天,多人视频会议功能加强版本(Fms3和Flex开发(附源码)) 中文说明文档和代码, 简单明了好资料
python库。 资源全名:mypy-boto3-fms-1.17.70.post2.tar.gz