我正在开发一个聊天应用程序,使用openfire作为xmpp服务器,strophe.js作为客户端库,并在ubuntu上使用ruby on rails。
问题是strophe.js连接到openfire,但给出自动失败状态,并且不创建任何users.It总是返回状态4(自动失败)。
openfire正在>>本地主机上运行:9090
运行在>>本地主机上的rails应用程序:3000
运行在上的BOSH服务:7070/ >> -bind/
代码:-
<script>
var BOSH_SERVICE = 'http://localhost:7070/http-bind/';
var connection = null;
jQuery('#connect').click(function(){
connection = new Strophe.Connection(BOSH_SERVICE);
connection.connect($('#enter_id').get(0).value + "@localhost", null, onConnect);
});
function onConnect(status)
{
console.log("status is >> " + status);
if(status == 5){
console.log("inside if status is >> " + Strophe.Status.CONNECTED);
console.log("onConnect >> " + status);
connection.send($pres().tree());
connection.addHandler(notifyUser, null, 'message', "chat");
console.log("onConnect >> handler added");
}
}
function notifyUser(msg)
{
console.log("notifyUser >> " + msg);
// if (msg.getAttribute('from') == "testuser@127.0.0.1/pingstream") {
var elems = msg.getElementsByTagName('body');
var body = elems[0];
jQuery('#chat_msg').append(Strophe.getText(body));
// }
return true;
}
jQuery('#send_msg').click(function(){
var msg_to_send = $msg({
to: jQuery('#send_to').val() + "@localhost",
from: connection.jid,
type: "chat"
}).c("body").t("hi!");
connection.send(msg_to_send.tree());
});
</script>请帮帮忙。
发布于 2013-07-31 20:28:47
@amirinder007您在代码中提供了错误的servername。我研究了你的代码,发现你提供了本地主机和127.0.0.1,而不是你写的配置了openfire的服务器name(Hostname),你还在openfire管理控制台的主页上看到它的名称,如我的电脑-pc作为个人电脑的名称。
发布于 2013-08-06 23:08:23
我猜这里提供的servername是错误的。尝试将其设置为注册到openfire而不是localhost的hostname。
https://stackoverflow.com/questions/17311901
复制相似问题