1
votes

Im developing a chat application with openfire as xmpp server and strophe.js as client library and using ruby on rails on ubuntu.

Problem is that strophe.js connects to the openfire but gives AUTHFAIL status and donot create any users.It always return status 4 (AUTHFAIL).

openfire is running on >> localhost:9090
rails application running on >> localhost:3000
BOSH service running on >> localhost:7070/http-bind/

Code:-

    <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.

2
Please post stanzas body, both request and response.Milos Jovanovic
Did you test if Openfire works with some existing XMPP client, like Spark?Milos Jovanovic

2 Answers

0
votes

@amirinder007 You provide wrong servername in your code. I have study your code and find that you provide localhost and 127.0.0.1 instead you write server name(Hostname) that is configured with openfire and you also see on home page of admin console of openfire and its name like Mycomputer-pc as name of personal computer.

0
votes

The servername provided here is wrong, I guess. Try setting it as the hostname registered with openfire and not localhost.