XMPP环境搭建常见错误
来源:互联网 发布:凤凰卫视直播软件apk 编辑:程序博客网 时间:2024/04/30 03:33
(1)首先安装openfire时,不要忘记开启脚本语法:
(2)建立用户安装客户端进行测试,我使用的是Psi不过这个不要忘记设置host,在Connetion指定手动连接host
(3)openfire在重启时候可能出现log找不到错误,使用管理员账号运行就好了。。
(4)下面是连接的设置部分:
首先下载Strophe.js使用里面的Examples的例子就行了。。。
在apache中设置反向代理:
开启proxy proxy_http 模块,在文件最后添加以下代码:ProxyRequests OffProxyPass /http-bind http://127.0.0.1:7070/http-bind/ProxyPassReverse /http-bind http://127.0.0.1:7070/http-bind/(5)设置Bosh_SERVICE = ‘/http-bind'
现在可以启动basic.html查看到如下
(6)建立测试通信程序: 修改basic.html如下所示。。。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Strophe.js Echobot Example</title> <script language='javascript' type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script> <script language='javascript' type='text/javascript' src='../strophe.js'></script> <script language='javascript' type='text/javascript' src='basic.js'></script> <style> body {font-size:9pt} #his {width:620px; height:200px;overflow:auto; border: 1px dashed #000000;folat:left;} #ros {width:620px; height:100px;overflow:auto; border: 1px dashed #000000;folat:left;} .editbox,input[type="text"],input[type="password"] { background: #ffffff; border: 1px solid #b7b7b7; color: #003366; cursor: text; font-family: "arial"; font-size: 9pt; height: 18px; padding: 1px; } .multibox { background: #f8f8f8; border-bottom: #B7B7B7 1px solid; border-left: #B7B7B7 1px solid; border-right: #B7B7B7 1px solid; border-top: #B7B7B7 1px solid; color: #000000; cursor: text; font-family: "Arial"; font-size: 9pt; padding: 1px; } </style></head><body> <p></p> <div id='login'> <form name='cred'> <label for='jid'>JID:</label> <input type='text' id='jid' value="user1@localhost" /> <label for='pass'>Password:</label> <input type='password' id='pass' value="123456"/> <input type='button' id='connect' value='connect' /> </form> </div> <p></p> <div id="his"></div> <p></p> <div id="inputarea"> <label for='tojid'>TOJID:</label> <input type='text' id='tojid' value="admin@testserver"/> <br/> <textarea id="msg" rows="3" cols="120" class="multibox"></textarea> <input type="button" id="send" value="send" /> <input type="button" id="roster" value="roster" /> </div> <hr /> <div id='log'></div></body></html>修改basic.js代码如下
var BOSH_SERVICE = '/http-bind';var connection = null;var toId=null;var fromId=null; Strophe.log = function (level, msg) { //$('#log').append('<div></div>').append(document.createTextNode(msg));}; function rawInput(data){ log('RECV: ' + data);} function rawOutput(data){ log('SENT: ' + data);} function log(msg){ //$('#log').append('<div></div>').append(document.createTextNode(msg));} function onConnect(status){ if (status == Strophe.Status.CONNECTING) { log('Strophe is connecting.'); } else if (status == Strophe.Status.CONNFAIL) { log('Strophe failed to connect.'); $('#connect').get(0).value = 'connect'; } else if (status == Strophe.Status.DISCONNECTING) { log('Strophe is disconnecting.'); } else if (status == Strophe.Status.DISCONNECTED) { log('Strophe is disconnected.'); $('#connect').get(0).value = 'connect'; } else if (status == Strophe.Status.CONNECTED) { log('Strophe is connected.'); connection.addHandler(onMessage, null, 'message', null, null, null); //connection.addHandler(onRoster, null , 'iq' , null , null , null); connection.send($pres().tree()); }} /* * 消息处理 */function onMessage(msg) { to = msg.getAttribute('from'); var from = msg.getAttribute('from'); var type = msg.getAttribute('type'); var elems = msg.getElementsByTagName('body'); if (type == "chat" && elems.length > 0) { var body = elems[0]; appendToHis(new Date().toLocaleTimeString() + ' ' + from + ' say: ' + Strophe.getText(body)); } return true;} function appendToHis(msg){ $('#his').append('<div>' + msg + '</div>'); $('#his').attr("scrollTop", $('#his').attr("scrollHeight"));} $(document).ready(function () { connection = new Strophe.Connection(BOSH_SERVICE); connection.rawInput = rawInput; connection.rawOutput = rawOutput; $('#connect').bind('click', function () { var button = $('#connect').get(0); if (button.value == 'connect') { button.value = 'disconnect'; //获取用户名和密码 fromId = $('#jid').val(); toId = $('#tojid').val(); //连接服务器 connection.connect($('#jid').get(0).value, $('#pass').get(0).value, onConnect); } else { button.value = 'connect'; connection.disconnect(); } }); $('#send').bind('click', function () { msg=$('#msg').val(); toId = $('#tojid').val(); var reply = $msg({to: toId, from: fromId , type: 'chat'}).cnode(Strophe.xmlElement('body', '' ,msg)); connection.send(reply.tree()); appendToHis(new Date().toLocaleTimeString() + " Me: " + msg); $('#msg').val(''); }); $('#msg').keypress(function(e){ if(e.which==13){ $('#send').click(); } }); });现在就可以使用网页打开。。。两个客户端就可以通信了。。可以打开log查看输出信息
0 0
- XMPP环境搭建常见错误
- QT环境搭建及常见错误
- iOS 搭建 XMPP实现环境
- XMPP聊天客户端环境搭建
- iOS 搭建 XMPP实现环境
- [XMPP]xampp服务器环境搭建
- iOS 搭建 XMPP实现环境
- XMPP服务器环境的搭建
- XMPP通讯环境的搭建
- iOS之XMPP环境搭建
- IPOP-VPN环境搭建,ejabberd XMPP搭建
- Android 环境搭建,Helloworld以及常见错误处理,最新版哦
- 搭建Android源码编译环境及编译常见错误
- hbase:伪分布环境搭建及常见错误解决方法
- lua环境搭建 + 常见错误解决 windows + linux双版
- tufao环境搭建-记常见错误一例
- iOS XMPP开发环境的搭建
- iOS XMPP开发环境的搭建
- 大数据量表的优化查询 - 发条
- TortoiseGit 保存用户名密码的方法
- sqlite的初步使用,JAVA + C#(winform)
- 环境变量的配置
- 六类qsort排序方法
- XMPP环境搭建常见错误
- sscanf函数与sscanf_s函数
- 安装HBase 0.94.6-cdh4.5.0
- JBoss bundle和Apache 2.2.x环境下配置mod_proxy
- Wi-Fi Display analysis (一)framework
- 自动行号功能实现不同方法研究
- 网址收藏(不断更新中)
- 烫烫烫烫与屯屯屯屯…
- linux下动态库/静态库 链接路径设置问题