android - Unable to connect to xmpp server in phonegap with openfire server using strophe.js -
i new phonegap.iam using coredova latest version 2.9.0 developing chatting application connecting xmpp server open fire server..i have been searching related storph.js code in phonegap since last 2 days.i didn't running code in phonegap,getting status '1' means connecting..can helps...thanks in advace.
<html> <head> <title> phonegap xmpp tutorial </title> </head> <script type="text/javascript" charset="utf-8" src="coredova-2.9.0.js"></script> <script type="text/javascript" charset="utf-8" src="strophe.js"></script> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script> <script> function connect() { var username="xxx"; var host_domain="xxx"; var password="xxx"; var bosh_service = "xxxxx"; connection = new strophe.connection(bosh_service); connection.connect(username + "@" + host_domain, password, onconnect); } function onconnect(status) { alert(status); if (status == strophe.status.connected) { alert("connected"); }else if (status == strophe.status.disconnected) { console.log("strophe disconnected."); } } </script> <body> <button onclick="connect();">click</button> </body> </html>
see if have configured url (bosh_service), openfire default url "127.0.0.1:7070/http-bind/" use console show strophe sends messages xmpp server , receives server debug(look @ "exploring xmpp protocol: debugging console"), can helpful book “professional xmpp - programming javascript , jquery”.
basic strophe example:
<!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> //url server openfire, default 'http://server-ip:7070/http-bind/' var bosh_service = 'http://bosh.metajack.im:5280/xmpp-httpbind' var connection = null; function log(msg) { $('#log').append('<div></div>').append(document.createtextnode(msg)); } function rawinput(data) { log('recv: ' + data); } function rawoutput(data) { log('sent: ' + data); } function onconnect(status) { if (status == strophe.status.connecting) { log('strophe connecting.'); } else if (status == strophe.status.connfail) { log('strophe failed connect.'); $('#connect').get(0).value = 'connect'; } else if (status == strophe.status.disconnecting) { log('strophe disconnecting.'); } else if (status == strophe.status.disconnected) { log('strophe disconnected.'); $('#connect').get(0).value = 'connect'; } else if (status == strophe.status.connected) { log('strophe connected.'); connection.disconnect(); } } $(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'; connection.connect($('#jid').get(0).value, $('#pass').get(0).value, onconnect); } else { button.value = 'connect'; connection.disconnect(); } }); }); </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>
check if http binding enabled in server settings. can confirm navigating "server-ip:7070" web browser. message 1 "openfire http binding service" shown when http binding enabled , listening @ port (7070 default).
to change http binding settings open server settings web interface , navigate "server->server settings->http binding".
Comments
Post a Comment