CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Detect user's connection speed (http://www.codingforums.com/showthread.php?t=272181)

johnsmith153 09-03-2012 11:21 PM

Detect user's connection speed
 
I want to detect the user's connection speed to offer an improved website experience. As an example, use 20 records per page pagination, but allow the detection script to change that to higher or lower (as well as other things).

How is the best way to do this, and can someone point me in the right direction?

Thanks.

_Aerospace_Eng_ 09-03-2012 11:29 PM

It can't be done in Javascript. Possibly flash or Java.

johnsmith153 09-03-2012 11:34 PM

Rubbish, and it's JavaScript and Flash, not Javascript and flash.

rnd me 09-04-2012 01:11 AM

using this, i'd say anything over 50 would be fast, anything over 500 would be really fast:

Code:


function getRate() {
        var sum = 0;
        for (var i = 0; i < 5; i++) {
                var d1 = new Date;
                var X = new XMLHttpRequest;
                X.open("GET", "?" + Math.random(), false);
                X.send();
                var d2 = new Date;
                sum += (d2 - d1);
        }//next
        return Math.floor(X.responseText.length / (sum / 5));
} /* end getRate() */

alert(
  getRate() + "KBs"
)

remember, a modem is 5 or 6 on a good day...

not too difficult to program either...

_Aerospace_Eng_ 09-04-2012 01:22 AM

Quote:

Originally Posted by johnsmith153 (Post 1266676)
Rubbish, and it's JavaScript and Flash, not Javascript and flash.

Then why didn't you answer your own question? It would seem to me if you think it is "rubbish" then you would know how to do it on your own. Learn to be considerate of the people trying to help. Good luck. Hope you find what you are looking for, oh wait you probably don't need any help.

rnd me 09-04-2012 01:24 AM

Quote:

Originally Posted by _Aerospace_Eng_ (Post 1266675)
It can't be done in Javascript.

please don't ever say that again.

VIPStephan 09-04-2012 01:51 AM

Quote:

Originally Posted by rnd me (Post 1266709)
please don't ever say that again.

How do bake a cookie with JavaScript? ;)

johnsmith153 09-04-2012 04:33 AM

Quote:

Originally Posted by rnd me (Post 1266705)
using this, i'd say anything over 50 would be fast, anything over 500 would be really fast:

Code:


function getRate() {
        var sum = 0;
        for (var i = 0; i < 5; i++) {
                var d1 = new Date;
                var X = new XMLHttpRequest;
                X.open("GET", "?" + Math.random(), false);
                X.send();
                var d2 = new Date;
                sum += (d2 - d1);
        }//next
        return Math.floor(X.responseText.length / (sum / 5));
} /* end getRate() */

alert(
  getRate() + "KBs"
)

remember, a modem is 5 or 6 on a good day...

not too difficult to program either...

Brilliant. Thanks.

Only thing is:
Code:

new Date;
should be:
Code:

new Date().getTime() / 100;
I've tested and it works great on many occasions and on many different devices.

So much better than the image download scripts I keep seeing.

Thanks again.

rnd me 09-04-2012 07:16 AM

Quote:

Originally Posted by johnsmith153 (Post 1266739)
Brilliant. Thanks.

Only thing is:
Code:

new Date;
should be:
Code:

new Date().getTime() / 100;
I've tested and it works great on many occasions and on many different devices.

So much better than the image download scripts I keep seeing.

Thanks again.

my units are KiloBytes per second, you might be looking for KiloBits per second, which is more common in ISP advertising.

i should also mention that you might consider is keeping track of the total time, subtracting delay and the dividing by 5. That math yields your average latency, another quality of service indicator.

johnsmith153 09-04-2012 10:49 AM

Thanks, but your script returned a score of 1-4 units depending on how I tested it (and I tested it on lots of different connection speeds).

Changing it as I have returns 1-400 units.

It definitely needed changing. You said that anything over 50 would be fast, and 500 would be really fast. Your script would never return anything near 50, let alone 500.

Quote:

i should also mention that you might consider is keeping track of the total time, subtracting delay and the dividing by 5. That math yields your average latency, another quality of service indicator.
Good point. Thanks.

rnd me 09-04-2012 08:38 PM

Quote:

Originally Posted by johnsmith153 (Post 1266824)
Thanks, but your script returned a score of 1-4 units depending on how I tested it (and I tested it on lots of different connection speeds).

Changing it as I have returns 1-400 units.

It definitely needed changing. You said that anything over 50 would be fast, and 500 would be really fast. Your script would never return anything near 50, let alone 500.


Good point. Thanks.

i'm glad you got it working, but when i run the code in post #4 at home i get about 60-90 (crappy wifi). at work i get ~180...


All times are GMT +1. The time now is 07:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.