bertrandmartel / speed-test-lib

:cloud: JSpeedTest : speed test client library for Java/Android
MIT License
381 stars 119 forks source link

Speed test for pages #29

Closed DimaDDM closed 7 years ago

DimaDDM commented 7 years ago

Hello. Can you add feature for measure loading web pages? Like this for example:

    try
    {
        URL url_t = new URL(url);
        URLConnection connection = url_t.openConnection();
        connection.connect();
        InputStream input = new BufferedInputStream(connection.getInputStream());

        int BUFFER_SIZE = 1024;
        byte buffer[] = new byte[BUFFER_SIZE];
        long start = System.currentTimeMillis();
        long size = 0;
        int bytes;

        while ((bytes = input.read(buffer, 0, BUFFER_SIZE)) > 0)
        {
            size += bytes;
            long delta_time = System.currentTimeMillis() - start;
            double speed = 10000F * size / delta_time;
        }

        input.close();
    }
    catch(Exception ignored) {}
bertrandmartel commented 7 years ago

Not sure what you call loading, do you mean downloading ? You can download page served in the http protocol with the lib for instance :

speedTestSocket.startDownload("stackoverflow.com", 80, "/users/22656/jon-skeet");

Do you have a specific example which is not working ?

DimaDDM commented 7 years ago

Okay. For example speedTestSocket.startDownload("iptools.su", 80, "/help", UPDATE); I got 301 error.

bertrandmartel commented 7 years ago

301 & 302 are now redirected to the location specified in Location header (either relative or absolute value). Let me know if you have other issues