ejabberd XMPP连接使用strophejs失败
我试图在服务器端使用ejabberd运行代码。这是我的连接代码:ejabberd XMPP连接使用strophejs失败,xmpp,ejabberd,strophe,Xmpp,Ejabberd,Strophe,我试图在服务器端使用ejabberd运行代码。这是我的连接代码: $(document).bind('connect', function (ev, data) { console.log("connect "+JSON.stringify(data)); var conn = new Strophe.Connection("http://localhost:5280/http-bind"); conn.connect(data.jid, data.password,
$(document).bind('connect', function (ev, data) {
console.log("connect "+JSON.stringify(data));
var conn = new Strophe.Connection("http://localhost:5280/http-bind");
conn.connect(data.jid, data.password, function (status) {
console.log("status"+status);
if (status === Strophe.Status.CONNECTED) {
$(document).trigger('connected');
} else if (status === Strophe.Status.DISCONNECTED) {
$(document).trigger('disconnected');
}
});
Hello.connection = conn;
});
我得到状态=1
。几分钟后,它开始持续显示:
Uncaught错误:11,flXHR::abort():失败,abort()调用未能完成。
我的ejabberd正在http://localhost:5280/admin/
和admin@ejab
是管理员用户
以下是完整代码:
<!DOCTYPE html>
<html>
<head>
<title>Strophe.js Basic Example</title>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script>
<script src='../strophe.js'></script>
<!-- <script src='scripts/flXHR.js'></script>
<script src='scripts/strophe.flxhr.js'></script>-->
<script src='basic.js'></script>
</head>
<body>
<div id='login' style='text-align: center'>
<form name='cred'>
<label for='jid'>JID:</label>
<input type='text' id='jid'>
<label for='pass'>Password:</label>
<input type='password' id='pass'>
<input type='button' id='connect' value='connect'>
</form>
</div>
<hr>
<div id='log'></div>
</body>
</html>
输出为:
Strophe is connecting.
SENT: <body rid='745165534' xmlns='http://jabber.org/protocol/httpbind' to='ejab' xml:lang='en' wait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>
Strophe正在连接。
发送:
状态=1表示连接。这主要意味着无法访问BOSH服务器
输入
在Chrome上看看你是否真的能到达BOSH服务器
如果您的服务器实际上是localhost(存储hello.html的计算机)上的主机,您可以注释掉
flXHR.js和strophe.flXHR.js位于hello.html的头部,因为它们用于跨域访问
e、 g.在您的桌面上使用hello.html,并使用托管在另一台计算机上的域(xmpp服务器),由于跨域访问安全性,Chrome不允许使用该域
如果hello.html和xmpp服务器都位于同一台计算机上,则不会出现跨域问题
无论如何,这两个文件似乎无法克服几年前Chrome浏览器设置的跨域访问限制。使用Chrome的参数--“禁用web安全”可以为测试提供跨域访问
最后,在Chrome浏览器上,右键单击选择“Inspect Element”->Network,重新加载hello.html并登录以检查这些http绑定访问。他们应该给出错误的提示。您使用的是哪个版本的ejabberd服务器?您似乎有跨域问题,但这是在最新版本上自动处理的,所以我猜您使用的是旧的ejabberd版本。您使用的是哪个浏览器?chrome版本40.0.2214.91(64位)我已更新了我的问题,这将帮助您了解我的情况。我在mozilla中试用过,输出结果就像是Strophe正在连接。已发送:当我浏览
http://localhost:5280/http-bind/
它向我展示了一个页面,上面写着ejabberd mod_http_bindAn XMPP over BOSH的实现(XEP-0206)。这个网页只提供信息。要使用HTTP绑定,您需要一个支持它的Jabber/XMPP客户端。
Strophe is connecting.
SENT: <body rid='745165534' xmlns='http://jabber.org/protocol/httpbind' to='ejab' xml:lang='en' wait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>