2013-06-26 45 views
1

我正在开发一个使用openfire作为xmpp服务器和strophe.js作为客户端库的聊天应用程序,并在ubuntu上使用Ruby on Rails。Strophe.js始终给予AUTHFAIL状态

问题是,strophe.js连接到openfire,但给AUTHFAIL状态,并不创建任何用户。它始终返回状态4(AUTHFAIL)。

的Openfire上运行本地主机>>:9090
Rails应用程序上运行的本地主机>>:3000
BOSH服务上运行的本地主机>>:7070/HTTP绑定/

代码: -

<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') == "[email protected]/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> 

Plz help。

+0

请张贴节体,请求和响应。 –

+0

您是否测试Openfire是否可以与Spark等一些现有的XMPP客户端一起使用? –

回答

0

@ amirinder007您在代码中提供了错误的servername。我学习你的代码,并发现你提供本地主机127.0.0.1而不是你写配置了Openfire的服务器名称(主机名),你也看到的Openfire的管理控制台的主页和它的名字一样上Mycomputer-pc作为个人电脑的名称。

0

这里提供的servername是错误的,我想。尝试将它设置为使用openfire注册的hostname,而不是localhost