- 浏览: 1454779 次
- 性别:
- 来自: 青岛人在北京
文章分类
最新评论
-
yhxf_ie:
azheng270 写道 永远是0知道答案了, inser ...
使用MySQL的LAST_INSERT_ID -
yhxf_ie:
insert了还是0... 可能还要设置些什么?
使用MySQL的LAST_INSERT_ID -
一如年少:
123123
Flex使用ribbit.com的服务给手机发送短信SMS -
pointdew:
poincare 写道您好,请教一个问题,如果我的 swf 文 ...
Flex:使用FlexPaper显示PDF文档 -
pointdew:
swf远程加载问题 : flexpaper无法加载http方式 ...
Flex:使用FlexPaper显示PDF文档
先解释几个名词
XMPP: (eXtensible Messaging and Presence Protocol) XMPP的前身是Jabber,一个开源形式组织产生的网络即时通信协议。XMPP目前被IETF国际标准组织完成了标准化工作。是目前主流的四种IM(IM:instant messaging,即时消息)协议之一,其他三种分别为:IMPP、PRIM、SIP(SIMPLE)。
XIFF: XMPP Implementation For Flash. (一个ActionScript的XMPP类库)
Openfire: (原名Wildfire) 基于Java的开源实时协作(RTC)服务器,使用XMPP(Jabber)协议。
Google推出的Google Talk就是基于XMPP的IM软件。所以我想使用Flex也开发一个基于XMPP的聊天程序。现在已经有了很好的开源服务器Openfire http://www.igniterealtime.org/projects/openfire/index.jsp 支持中文哦。
另外还有一套XIFF API,专为flash开发XMPP应用,但现在XIFF2.0是用AS2写的,而Flex2是基于AS3的,幸运的是有人已经写了一个基于AS3的实现。http://svn.igniterealtime.org/svn/repos/xiff/branches/xiff_as3_flexlib_beta1/
要开发Flex + Openfire的系统,首先要安装Openfire服务器,安装很简单,具体看安装手册http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/install-guide.html
安装在本机的Openfire启动后,可以通过http://localhost:9090 管理
好,现在开始开发Flex客户端。因为现在XIFF_AS3的文档几乎没有,所以只能通过XIFF2的例子,和Smack API(for java的)来学习。XIFF的核心是XMPPConnection,它基本是围绕flash.net.XMLSocket写的。首先创建一个Flex项目并引入 XIFF.swc
登录服务器比较简单
var connection : XMPPConnection = new XMPPConnection();
connection.server = 服务器名
connection.port = 服务器端口号
connection.username = 用户名
connection.password = 密码
connection.connect("flash");
下面是一个简单的小例子
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
- creationComplete="initApp()">
- <mx:Script>
- [CDATA[
- import org.igniterealtime.xiff.events.RoomEvent;
- import mx.controls.Alert;
- import org.igniterealtime.xiff.events.MessageEvent;
- import org.igniterealtime.xiff.core.XMPPConnection;
- import org.igniterealtime.xiff.conference.Room;
- import org.igniterealtime.xiff.events.LoginEvent;
- import org.igniterealtime.xiff.data.*;
- public const SERVER_NAME : String = "wangcheng";
- public const CHATROOM : String = "chatRoom1";
- private var chatRoom : Room;
- private var connection : XMPPConnection;
- private function initApp():void {
- connection = new XMPPConnection();
- connection.addEventListener(LoginEvent.LOGIN, onLogin);
- }
- private function doLogin():void {
- if (!connection.isLoggedIn()) {
- connection.username = username.text;
- connection.password = password.text;
- connection.server = SERVER_NAME;
- connection.port = 5222;
- connection.connect("flash");
- if(connection.isLoggedIn()){
- chatContent.htmlText += "Welcome " + username.text + "<br/>";
- }
- } else {
- connection.disconnect();
- }
- }
- private function onLogin(event):void {
- inputMsg.enabled = true;
- sendBtn.enabled = true;
- chatRoom = new Room( connection );
- chatRoom.setRoomJID(connection.getJID());
- chatRoom.roomName = CHATROOM;
- chatRoom.nickname = connection.username;
- chatRoom.conferenceServer = "conference." + SERVER_NAME;
- chatRoom.join();
- chatRoom.addEventListener(RoomEvent.GROUP_MESSAGE, groupMessage);
- }
- private function groupMessage(event):void {
- displayUserMessage(getNickName(event.data.from) , event.data.body );
- }
- private function getNickName(jid : String) : String {
- var name = jid.split("/")[1];
- if (name == null) {
- name = "Message";
- }
- return name;
- }
- private function displayUserMessage(user:String, message:String) : void {
- var fontColor : String = "#002bd2";
- if (user == chatRoom.nickname) {
- fontColor = "#8e2800";
- }
- chatContent.htmlText += "<font color='" + fontColor + "'><b>" + user + ":</b> " + message + "</font><br />";
- }
- private function sendMsg():void {
- if (inputMsg.text != "") {
- chatRoom.sendMessage(inputMsg.text);
- inputMsg.text="";
- }
- }
- ]]
- </mx:Script>
- <mx:Label x="10" y="10" text="UserName"/>
- <mx:TextInput id="username" x="80" y="8" width="92"/>
- <mx:Label x="180" y="10" text="Password"/>
- <mx:TextInput id="password" x="244" y="8" width="99" displayAsPassword="true"/>
- <mx:Button x="351" y="8" label="Login" click="doLogin()"/>
- <mx:TextArea id="chatContent" x="10" y="36" width="397" height="171"/>
- <mx:TextInput id="inputMsg" enabled="false" x="12" y="215" width="333" enter="sendMsg()" />
- <mx:Button id="sendBtn" enabled="false" x="353" y="215" label="Send" click="sendMsg()" />
- </mx:Application>
参考
http://www.dgrigg.com/post.cfm/09/05/2006/XIFF-Actionscript-3-for-Flex-2
评论
请楼主指教
http://wangcheng.iteye.com/blog/153548
如今用JAVA连OPENFIRE也可以,但用XIFF3就不可以了。
你的OPENFIRE的型号是多少?是不是3.4.1?
var connection:XMPPConnection;
connection=new XMPPConnection();
connection.server="kenshinhu";
connection.port=5222;
connection.username="abcd";
connection.password="1234";
trace(connection.connect("flash"));
if(connection.isLoggedIn()){
trace("is login");
}else{
trace("isn't login");
}
我是用上面的代码来连接的。
SERVER_NAME是对应OPENFIRE服务上的服务器设置里的服务器名称对吗?我在OPENFIRE上也建了相应的用户了。。
但最后trace出来的值是isn't login咯。。。请求是不是还有别的要设置?
我试过CONNECTION去OPENFIRE,在和OPENFIRE下设的用户和密码一样下,也连不上,请问是怎样一回事?
像我这种脾气,心里的事得憋三天那是多么痛苦啊!呵呵
"新会员不能留言和评论" - 同感。三天后才能留言,使我见过的最恶心的限制。
可以到这里看看
http://www.igniterealtime.org/community/community/developers/xiff?start=0&view=discussions
里面有些例子。
我按着你的方法做了,又花了一些的时间研究了openfire和关于xiff,很遗憾没有正式为as3的版本.
我花了一个下午来实验你的方法,代码里有一些警告和错误,已经修改,可以正常运行,从服务器端可以看到用户已经登陆,可是对话的结果却总是显示不出来.在velloff的代码里面debug,发现你的程序的流程有一些问题,可惜velloff的那个as3的xiff没有说明文档和例子,未果~~~
带着多样的心情,给你留言,希望能有更好的机会一起探讨~~
期待你的下一篇文章.
我的hotmail和email是:maple_zl@hotmail.com
发表评论
-
Flex4中文视频教程 - RIAMeeting
2010-04-23 10:48 6759RIAMeeting翻译的Flex4中文视频教程, 地址 ht ... -
Flash Flex 开源游戏引擎
2010-03-28 21:18 7196今天去了 9RIA.com 的北京天地会活动, 会上介绍了一些 ... -
几十个 ActionScript 3.0 APIs for Flex, Flash, AIR
2009-12-22 11:54 4148开发过程中使用API可以节省时间,这里有几十个API,它们可以 ... -
Flex:使用FlexPaper显示PDF文档
2009-12-15 17:03 35399FlexPaper是一个开源的轻量级文档显示组件,被设计用来与 ... -
Flex白板画图例子
2009-06-21 18:56 8077这个程序是从公司2007年做的一个项目中抽取出来的部分代码完成 ... -
Flex使用ribbit.com的服务给手机发送短信SMS
2009-06-13 15:10 3052http://www.ribbit.com/ 可以将语音通 ... -
Flex鼠标移到Label上显示手型useHandCursor
2009-05-08 11:28 5639要想鼠标在Label上显示为手型,需要设置3个属性 & ... -
Flex3与EJB3的WebService通讯
2009-04-18 14:20 3706项目中使用了Flex3 + EJB3 + WebService ... -
CodeBehind and DI 分离MXML中的ActionScript
2009-04-09 20:27 2696你是否开始厌倦在 mxml 中写 <mx:Script& ... -
De MonsterDebugger开源的Flex运行时调试器
2009-04-09 15:53 4052De MonsterDebugger http://www. ... -
Flex组件中PopUpManager在全局坐标中心弹出窗口
2009-04-02 19:52 4979在Flex的某个组件中使用 var somePopupWi ... -
在JBoss4.2中放置crossdomain.xml解决flex3跨域访问WebService问题
2009-03-31 20:54 5712Flex访问部署在JBoss4.2上的WebService时报 ... -
使用Flex3的Import Web Service功能
2009-03-28 21:36 2443在FlexBuilder的菜单上选 Data -> I ... -
使用KitchenSync和CASALib延迟(delay)执行Flex的function
2009-02-25 18:26 3388要延迟(delay)执行Flex的function,或按顺序同 ... -
Flex中解决Error #2044 securityError
2009-02-25 16:54 6581在FlexBuilder中运行app没有问题,复制项目的 bi ... -
Flex中加载Flash CS3制作的swf文件
2009-02-14 20:37 6264Flex加载Flash CS3制作的swf文件, 看Demo ... -
Flex视频教学 (RIAMeeting翻译Flex in a Week)
2008-12-01 00:03 4294此系列Flex视频教学是基于Adobe官方的Flex in a ... -
Flex中文API (Adobe官方)
2008-08-19 10:03 21488Adobe推出的中文API http://livedocs ... -
RIAMeeting - Flash Media Server 3
2008-07-26 22:08 3238这次是RIAMeeting的第七次 ... -
Mate Flex Framework
2008-07-22 11:29 3133Mate 是一个基于标签(tag-based)的事件驱动(ev ...
相关推荐
swf文件 博文链接:https://wangcheng.iteye.com/blog/153548
android xmpp chat 聊天程序
Flex实现的xmpp消息发送接收,利用xiff插件实现,可以在android、ios等手机运行,也可以直接在ie上运行
基于XMPP协议的WEBIM 简单实现,如有开发openfire+spark/jwchat的可以参考
初步学习XMPP协议,并完成了一个基于XMPP的简单即时通信Demo。
基于xmpp+asmack+openfire的安卓客户端高仿qq,支持好友添加,文本,动态表情,图片,位置类型的信息收发;
基于XMPP实现android客户端与服务器的交互(源码)
一个开源的基于XMPP协议的仿QQ的Andorid端聊天源码(功能非常全)。这是一个开源中国社区的开放源码,放在CSDN上方便下载。
基于XMPP协议的手机多方多端即时通讯方案,包括详细的介绍和解决方案
本项目是一套基于android+asmack+openfire+xmpp的安卓即时聊天服务端,项目直连google talk服务器,可以使用谷歌帐号登录客户端,测试需要至少两个谷歌帐号。在程序里添加好友即可聊天。聊天核心功能使用的smack库
本资源是自己写的利用XMPP协议进行聊天的软件,界面实现采用Qt,功能和QQ很类似,对学习XMPP协议和Qt很有帮助。
XmppIm 基于XMPP实现一个iOS IM应用。支持文字,图片,语音聊天
初步学习XMPP协议,并完成了一个基于XMPP的简单即时通信Demo。
基于XMPP协议实现一套Socket通信程序,解决服务器多IP、多网卡自动识别的问题(C/S都带,VS2013打开,可学习,也可直接使用,物超所值)
Android基于xmpp即时通讯软件,界面简洁大方,功能简单小巧,bug倒是不多不少。 编码方式是utf-8,不能直接导入eclipse,请自己新建一个工程,将源码覆盖过去,并将编码方式修改为utf-8。 了解更多,请移步:...
基于XMPP协议的类似QQ的即时通信demo 简单实现了 注册,登录,添加好友,删除好友,好友的通信 包括发文本,图片和声音。
androidpn客户端需要用到一个基于java的开源XMPP协议包asmack,这个包同样也是基于openfire下的另外一个开源项目smack,不过我们不需要自己编译,可以直接把androidpn客户端里面的asmack.jar拿过来用。客户端利用...
安卓即时通讯,基于XMPP,详细介绍请查看本人博客:http://blog.csdn.net/baiyuliang2013