Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > BOOK: Professional XMPP Programming with JavaScript and jQuery
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional XMPP Programming with JavaScript and jQuery
This is the forum to discuss the Wrox book Professional XMPP Programming with JavaScript and jQuery by Jack Moffitt; ISBN: 978-0-470-54071-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional XMPP Programming with JavaScript and jQuery section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 16th, 2013, 11:25 PM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default Not all browsers successfully establish a connection

I just got started with XMPP, so please bare with me if I don't make much sense. I built a simple script to connect to the jabber.org server, based on the hello.js example in chapter 3 of the book. I uploaded the entire scripts folder to my server from the code resources, containing the strophe and affiliated libraries. Everything works perfectly in chrome and IE. However, connection can't be established on all other major desktop and mobile(iphone)browsers. i thought the strophe library was cross browser compatible. Anyone else has this issue or knows how to remedy the situation?

I'm going to include the modified hello.html, hello.js and hello.css files below.

hello.html or hello.php
Code:
<!DOCTYPE html>
<html>
  <head>
    <title>Hello - Chapter 3</title>
    
    <script type = "text/javascript" src="http://code.jquery.com/jquery-latest.js"> </script>



    <!--include JQM-->
    <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0-rc.1/jquery.mobile-1.3.0-rc.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.0-rc.1/jquery.mobile-1.3.0-rc.1.min.js"></script>



    <!--include strophe and flxhr-->

    <script src='scripts/strophe.js'></script>
    <script src='scripts/flXHR.js'></script>
    <script src='scripts/strophe.flxhr.js'></script>



    <link rel='stylesheet' href='hello.css'>

    <script src='hello.js'></script>


  </head>
  <body>
    <h1>Hello</h1>

    <div id='log'>
    </div>

    <!-- login dialog -->
    <div id='login_dialog' class=''>
      <label>JID:</label><input type='text' id='jid'>
      <label>Password:</label><input type='password' id='password'>
      <button>Submit</button>
    </div>
  </body>
</html>

hello.css

Code:
body {
    font-family: Helvetica;
}

h1 {
    text-align: center;
}

.hidden {
    display: none;
}

#log {
    width:300px;height:300px;color:red;border:1px solid black;
}

hello.js

Code:
var Hello = {
    connection: null,
    start_time: null,

    log: function (msg) {
        $('#log').append("<p>" + msg + "</p>");
    },

    send_ping: function (to) {
        var ping = $iq({
            to: to,
            type: "get",
            id: "ping1"}).c("ping", {xmlns: "urn:xmpp:ping"});

        Hello.log("Sending ping to " + to + ".");

        Hello.start_time = (new Date()).getTime();
        Hello.connection.send(ping);
    },

    handle_pong: function (iq) {
        var elapsed = (new Date()).getTime() - Hello.start_time;
        Hello.log("Received pong from server in " + elapsed + "ms.");

        Hello.connection.disconnect();
        
        return false;
    }
};

$(document).ready(function () {

	$('#login_dialog button').click(function(){


		Hello.log("connecting...");

                $(document).trigger('connect', {
                    jid: $('#jid').val(),
                    password: $('#password').val()
                });		

	});

});

$(document).bind('connect', function (ev, data) {
    var conn = new Strophe.Connection(
        "http://bosh.metajack.im:5280/xmpp-httpbind");

    conn.connect(data.jid, data.password, function (status) {
        if (status === Strophe.Status.CONNECTED) {
            $(document).trigger('connected');
        } else if (status === Strophe.Status.DISCONNECTED) {
            $(document).trigger('disconnected');
        }
    });

    Hello.connection = conn;
});

$(document).bind('connected', function () {
    // inform the user
    Hello.log("Connection established.");



    Hello.log("Full jid is: " + Hello.connection.jid + ".");

    Hello.log("Domain is: " + Strophe.getDomainFromJid(Hello.connection.jid) + ".");

    Hello.log("Resource is: " + Strophe.getResourceFromJid(Hello.connection.jid) + ".");

    Hello.log("Bare jid is: " + Strophe.getBareJidFromJid(Hello.connection.jid) + ".");

    Hello.connection.addHandler(Hello.handle_pong, null, "iq", null, "ping1");

    var domain = Strophe.getDomainFromJid(Hello.connection.jid);
    
    Hello.send_ping(domain);

});

$(document).bind('disconnected', function () {
    Hello.log("Connection terminated.");

    // remove dead connection object
    Hello.connection = null;
});

Thanks
  #2 (permalink)  
Old May 16th, 2013, 11:49 PM
Wrox Author
Points: 702, Level: 10
Points: 702, Level: 10 Points: 702, Level: 10 Points: 702, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

Mobile browsers don't support Flash. Remove strophe.flxhr.js and you should have better luck.
  #3 (permalink)  
Old May 17th, 2013, 12:40 AM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by metajack View Post
Mobile browsers don't support Flash. Remove strophe.flxhr.js and you should have better luck.
Thanks for that tip metajack. Now I can get a connection in all major browsers, mobile and desktop, with the exception on opera. That's a huge improvement.
  #4 (permalink)  
Old May 17th, 2013, 01:11 AM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by metajack View Post
Mobile browsers don't support Flash. Remove strophe.flxhr.js and you should have better luck.
Thanks for that tip metajack. Now I can get a connection in all major browsers, mobile and desktop, with the exception on opera. That's a huge improvement.
  #5 (permalink)  
Old May 17th, 2013, 01:44 AM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by metajack View Post
Mobile browsers don't support Flash. Remove strophe.flxhr.js and you should have better luck.
Thanks for that tip metajack. Now I can get a connection in all major browsers, mobile and desktop, with the exception on opera. That's a huge improvement.
  #6 (permalink)  
Old May 17th, 2013, 10:55 AM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by metajack View Post
Mobile browsers don't support Flash. Remove strophe.flxhr.js and you should have better luck.
After following your advice (removing strophe.flxhr.js), I got the application to establish a connection in most browsers with the exeption of opera. That was last night. This morning after waking up I was back to the original problem, couldn't establish a connection even though I hadn't changed the code. What could be the problem??
I added, the AUTHENTICATIG, CONNECTING, CONNFAIL, and AUTHFAIL, checks and discovered the problem was a connfail. I have just checked jabber's latest notice updates and the service seems to be running okay. Any ideas about what might be causing connfail when it wasn't a problem 10 hours ago?
  #7 (permalink)  
Old May 17th, 2013, 11:18 AM
Wrox Author
Points: 702, Level: 10
Points: 702, Level: 10 Points: 702, Level: 10 Points: 702, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

Check that the XMPP server is up, that the BOSH manager is up, and that you are not running cross domain somehow this morning.

The URL that services the HTML page of your application must be on the same port and domain as the BOSH endpoint, unless the browser and BOSH manager support CORS (IE does not for example).

This sounds to me like a cross domain access violation.
  #8 (permalink)  
Old May 17th, 2013, 11:40 AM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by metajack View Post
Check that the XMPP server is up, that the BOSH manager is up, and that you are not running cross domain somehow this morning.

The URL that services the HTML page of your application must be on the same port and domain as the BOSH endpoint, unless the browser and BOSH manager support CORS (IE does not for example).

This sounds to me like a cross domain access violation.
I think the XMPP server is up(at least it seems that way to me, I checked jabber's latest updates and there seems to be nothing wrong with the service). As for the BOSH manager, I have no clue how to go about checking that. Any links to any good tutorials? And if the BOSH could establish a connection last night but not today, does that mean that the port's value is somehow dynamic and can change on a whim?
  #9 (permalink)  
Old May 17th, 2013, 11:55 AM
Wrox Author
Points: 702, Level: 10
Points: 702, Level: 10 Points: 702, Level: 10 Points: 702, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

You can just visit the BOSH endpoint in your browser. You should seem some simple message there if it's working.
  #10 (permalink)  
Old May 17th, 2013, 12:01 PM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by metajack View Post
You can just visit the BOSH endpoint in your browser. You should seem some simple message there if it's working.
You'd have to forgive me for the silly questions since I'm brand new to XMPP. I'd have to take a deeper look at BOSH. Anyways, all of a sudden, I'm getting a connection again, but I'm still going to look into everything you suggested.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rewrite code from DAO to ADO To Establish Oracle Connection Pierre Doré Access VBA 1 August 10th, 2009 01:52 PM
LoadFromSqlServer - Can't establish connection mungdrool BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 March 8th, 2006 04:08 PM
Establish Com link to Webpage Mantis Pro VB 6 3 April 18th, 2005 04:14 AM
How to establish a sql server desktop engine pramos.21d SQL Server 2000 0 March 2nd, 2005 09:50 AM
Trying to establish an ID variable tkdk88 Dreamweaver (all versions) 3 January 25th, 2004 07:31 AM



All times are GMT -4. The time now is 09:39 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.