欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Flex2基于XMPP的chat程序 (一)

系統(tǒng) 2115 0

先解釋幾個名詞
XMPP : (eXtensible Messaging and Presence Protocol) XMPP的前身是Jabber,一個開源形式組織產(chǎn)生的網(wǎng)絡(luò)即時通信協(xié)議。XMPP目前被IETF國際標(biāo)準(zhǔn)組織完成了標(biāo)準(zhǔn)化工作。是目前主流的四種IM(IM:instant messaging,即時消息)協(xié)議之一,其他三種分別為:IMPP、PRIM、SIP(SIMPLE)。

XIFF : XMPP Implementation For Flash. (一個ActionScript的XMPP類庫)

Openfire : (原名Wildfire) 基于Java的開源實時協(xié)作(RTC)服務(wù)器,使用XMPP(Jabber)協(xié)議。

Google推出的Google Talk就是基于XMPP的IM軟件。所以我想使用Flex也開發(fā)一個基于XMPP的聊天程序。現(xiàn)在已經(jīng)有了很好的開源服務(wù)器Openfire http://www.igniterealtime.org/projects/openfire/index.jsp 支持中文哦。
另外還有一套XIFF API,專為flash開發(fā)XMPP應(yīng)用,但現(xiàn)在XIFF2.0是用AS2寫的,而Flex2是基于AS3的,幸運的是有人已經(jīng)寫了一個基于AS3的實現(xiàn)。 http://svn.igniterealtime.org/svn/repos/xiff/branches/xiff_as3_flexlib_beta1/

要開發(fā)Flex + Openfire的系統(tǒng),首先要安裝Openfire服務(wù)器,安裝很簡單,具體看安裝手冊 http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/install-guide.html

安裝在本機(jī)的Openfire啟動后,可以通過 http://localhost:9090 ?管理

好,現(xiàn)在開始開發(fā)Flex客戶端。因為現(xiàn)在XIFF_AS3的文檔幾乎沒有,所以只能通過XIFF2的例子,和Smack API(for java的)來學(xué)習(xí)。XIFF的核心是XMPPConnection,它基本是圍繞flash.net.XMLSocket寫的。首先創(chuàng)建一個Flex項目并引入 XIFF.swc

登錄服務(wù)器比較簡單
var connection : XMPPConnection = new XMPPConnection();
connection.server = 服務(wù)器名
connection.port = 服務(wù)器端口號
connection.username = 用戶名
connection.password = 密碼
connection.connect("flash");

下面是一個簡單的小例子

xml 代碼
  1. <? xml ? version = "1.0" ? encoding = "utf-8" ?> ??
  2. < mx:Application ? xmlns:mx = "http://www.adobe.com/2006/mxml" ? layout = "absolute" ??
  3. ???? creationComplete = "initApp()" > ??
  4. ??
  5. ???? < mx:Script > ??
  6. ????????[CDATA[ ??
  7. ????????????import?org.igniterealtime.xiff.events.RoomEvent; ??
  8. ????????????import?mx.controls.Alert; ??
  9. ????????????import?org.igniterealtime.xiff.events.MessageEvent; ??
  10. ????????????import?org.igniterealtime.xiff.core.XMPPConnection; ??
  11. ????????????import?org.igniterealtime.xiff.conference.Room; ??
  12. ????????????import?org.igniterealtime.xiff.events.LoginEvent; ??
  13. ????????????import?org.igniterealtime.xiff.data.*; ??
  14. ???????????? ??
  15. ????????????public?const?SERVER_NAME?:? String ?=? "wangcheng" ; ??
  16. ????????????public?const?CHATROOM?:? String ?=? "chatRoom1" ; ??
  17. ???????????? ??
  18. ????????????private?var?chatRoom?:?Room; ??
  19. ????????????private?var?connection?:?XMPPConnection; ??
  20. ???????????? ??
  21. ????????????private?function?initApp():void?{ ??
  22. ???????????????? connection ?=? new ?XMPPConnection(); ??
  23. ????????????????connection.addEventListener(LoginEvent.LOGIN,?onLogin); ??
  24. ????????????} ??
  25. ???????????? ??
  26. ????????????private?function?doLogin():void?{ ??
  27. ????????????????if?(!connection.isLoggedIn())?{ ??
  28. ???????????????????? connection.username ?=?username.text; ??
  29. ???????????????????? connection.password ?=?password.text; ??
  30. ???????????????????? connection.server ?=? SERVER_NAME ; ??
  31. ???????????????????? connection.port ?=? 5222 ; ??
  32. ????????????????????connection.connect("flash"); ??
  33. ????????????????????if(connection.isLoggedIn()){ ??
  34. ????????????????????????chatContent.htmlText?+=?"Welcome?"?+?username.text?+?" < br /> "; ??
  35. ????????????????????} ??
  36. ????????????????}?else?{ ??
  37. ????????????????????connection.disconnect(); ??
  38. ????????????????} ??
  39. ????????????} ??
  40. ???????????? ??
  41. ????????????private?function?onLogin(event):void?{ ??
  42. ???????????????? inputMsg.enabled ?=? true ; ??
  43. ???????????????? sendBtn.enabled ?=? true ; ??
  44. ??
  45. ???????????????? chatRoom ?=? new ?Room(?connection?); ??
  46. ????????????????chatRoom.setRoomJID(connection.getJID()); ??
  47. ???????????????? chatRoom.roomName ?=? CHATROOM ; ??
  48. ???????????????? chatRoom.nickname ?=? connection .username; ??
  49. ???????????????? chatRoom.conferenceServer ?=? "conference." ?+?SERVER_NAME; ??
  50. ???????????????? ??
  51. ????????????????chatRoom.join(); ??
  52. ????????????????chatRoom.addEventListener(RoomEvent.GROUP_MESSAGE,?groupMessage); ??
  53. ????????????} ??
  54. ???????????? ??
  55. ????????????private?function?groupMessage(event):void?{ ??
  56. ????????????????displayUserMessage(getNickName(event.data.from)?,?event.data.body?); ??
  57. ????????????} ??
  58. ??
  59. ????????????private?function?getNickName(jid?:?String)?:?String?{ ??
  60. ????????????????var? name ?=? jid .split("/")[1]; ??
  61. ????????????????if?( name ?==?null)?{ ??
  62. ???????????????????? name ?=? "Message" ; ??
  63. ????????????????} ??
  64. ????????????????return?name; ??
  65. ????????????} ??
  66. ???????????? ??
  67. ????????????private?function?displayUserMessage(user:String,?message:String)?:?void?{ ??
  68. ??
  69. ????????????????var?fontColor?:? String ?=? "#002bd2" ; ??
  70. ????????????????if?( user ?==?chatRoom.nickname)?{ ??
  71. ???????????????????? fontColor ?=? "#8e2800" ; ??
  72. ????????????????} ??
  73. ??
  74. ????????????????chatContent.htmlText?+=?" < font ? color = '"?+?fontColor?+?"' > < b > "?+?user?+?": </ b > ?"?+?message?+?" </ font > < br ? /> "; ??
  75. ????????????} ??
  76. ???????????? ??
  77. ????????????private?function?sendMsg():void?{ ??
  78. ????????????????if?(inputMsg.text?!=?"")?{ ??
  79. ????????????????????chatRoom.sendMessage(inputMsg.text); ??
  80. ???????????????????? inputMsg.text = "" ; ??
  81. ????????????????} ??
  82. ????????????} ??
  83. ??
  84. ????????]] ??
  85. ???? </ mx:Script > ??
  86. ??
  87. ??
  88. ???? < mx:Label ? x = "10" ? y = "10" ? text = "UserName" /> ??
  89. ???? < mx:TextInput ? id = "username" ? x = "80" ? y = "8" ? width = "92" /> ??
  90. ???? < mx:Label ? x = "180" ? y = "10" ? text = "Password" /> ??
  91. ???? < mx:TextInput ? id = "password" ? x = "244" ? y = "8" ? width = "99" ? displayAsPassword = "true" /> ??
  92. ???? < mx:Button ? x = "351" ? y = "8" ? label = "Login" ? click = "doLogin()" /> ??
  93. ???? < mx:TextArea ? id = "chatContent" ? x = "10" ? y = "36" ? width = "397" ? height = "171" /> ??
  94. ???? < mx:TextInput ? id = "inputMsg" ? enabled = "false" ? x = "12" ? y = "215" ? width = "333" ? enter = "sendMsg()" ? /> ??
  95. ???? < mx:Button ? id = "sendBtn" ? enabled = "false" ? x = "353" ? y = "215" ? label = "Send" ? click = "sendMsg()" ? /> ??
  96. </ mx:Application > ??

?

參考

http://www.dgrigg.com/post.cfm/09/05/2006/XIFF-Actionscript-3-for-Flex-2

Flex2基于XMPP的chat程序 (一)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日韩精品一区二区三区视频播放 | 天天做天天爱天天爽综合区 | 日本aⅴ在线观看 | 成人一区专区在线观看 | 亚洲欧美韩国日产综合在线 | 国产成人综合AV在线观看不止 | 亚洲视频在线看 | 欧美黑人激情 | 99精品欧美一区 | 久久99热这里只频精品6中文字幕 | 国产精品久久久久影院色老大 | 天天干天天摸 | 亚洲人成网站看在线播放 | 黄网站视频在线观看 | 一区二区三区在线 | 网站 | 亚洲精品乱码8久久久久久日本 | aaa一级毛片免费 | 欧美成人二区 | 色女生影院 | 精品久久香蕉国产线看观看亚洲 | 久久九九99热这里只有精品 | 精品欧美一区二区三区 | 国产午夜三级一区二区三桃花影视 | 青青草无限次破解版污 | 日韩成人在线播放 | 久久亚洲精品国产亚洲老地址 | 亚洲综合色婷婷 | 在线观看亚洲 | 亚洲精品第一综合99久久 | 六月丁香婷婷天天在线 | 国产一级一级国产 | 国产一区二区欧美 | 四虎影视网站 | 四虎影院在线播放 | 色洛色中文综合网站 | 国产综合50p| 免费区一级欧美毛片 | 亚洲天堂三级 | jiucao在线观看精品 | 女人午夜色又刺激黄的视频免费 | 成年人免费网站在线观看 |