先說說XIFF的進展,igniterealtime.org 自從2007-3-3刪除XIFF2后,一直在進行XIFF3的開發,現在每天都有更新,進展看似順利。而且有了個3.4.2版本,這篇文章中用的就是這個xiff的3.4.2版本.
使用 Openfire 3.4.3 版本
?
?
1.登錄
var _conn : XMPPSocketConnection; _conn.server = Server Name; _conn.username = Username; _conn.password = Password; _conn.connect("standard");
?
連接成功會觸發 ConnectionSuccessEvent.CONNECT_SUCCESS
登錄成功會觸發 LoginEvent.LOGIN
?
2.處理Roster
var _roster = new Roster(); _roster.connection = _conn;
Roster需要監聽的幾個重要event
RosterEvent.SUBSCRIPTION_REQUEST 當別人要加你為好友時
RosterEvent.USER_UPDATED 當你的好友更新了狀態時
添加一個聯系人
_roster.grantSubscription(聯系人JID, true);
拒絕別人添加好友的請求
_roster.denySubscription(請求人JID);
?
3.Message處理
需要監聽 _conn.addEventListener(MessageEvent.MESSAGE, messageHandler);
當收到消息時觸發 MessageEvent.MESSAGE
var m:Message = event.data as Message;
m.from 消息發送者
m.body 消息內容
m.type 消息類型 (Message.CHAT_TYPE, Message.GROUPCHAT_TYPE, Message.ERROR_TYPE 等)
?
發送消息
var message : Message = new Message(聯系人JID, null, null, null, Message.CHAT_TYPE, null); message.from = 發信人JID; message.body = 消息內容 //message.htmlBody = _conn.send(message);
?
4.注冊用戶
創建一個用戶
var regdata : Object = {}; regdata.username = 用戶名 regdata.password = 密碼 regdata.email = 郵箱 _conn.sendRegistrationFields( regdata, null );
_conn需要監聽 RegistrationSuccessEvent.REGISTRATION_SUCCESS, 當注冊成功時觸發.
?
5.Cross Domain
openfire的管理平臺中寫著: 端口5229? Flash Cross Domain
Security.loadPolicyFile("xmlsocket://Servername:5229");
?
openfire的crossdomain.xml是動態生成的,可以telnet看一下,在命令行中運行
telnet localhost 5229
會看到下面的內容
<?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <allow-access-from domain="*" to-ports="5222" /> </cross-domain-policy>
?
6.尚待解決的問題
xiff現在還沒實現XEP-0124
xiff直接連GTalk有問題(talk.google.com:5222)
?
參考
xiff 3.4.2
http://svn.igniterealtime.org/svn/repos/xiff/tags/xiff_3_4_2
xiff 3 API
http://paazio.wippiespace.com/xiff3doc/
中文翻譯計劃
http://wiki.jabbercn.org/space/start
Flex 2 with XIFF
http://www.darkcoding.net/software/xmpp-in-your-browser-flex-2-with-xiff/
XIFF ActionScript 3.0 Demo
http://www.velloff.com/?p=38
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
