Measuring Network Throughput Java/Android -


i'm doing app android, , want measure network throughput using http. far have done code makes http www.google.pt page. measure time between before , after request.

the problem: i'm measuring time of entire data exchange between server , app, overhead of tcp protocol. need time takes app receive webpage (useful data).

i have used wireshark see happens during request. useful data pdu's see. that's want.

http://imgur.com/aodpzrq

http://tinypic.com/r/15u6og/8

public static string get(string url){         inputstream inputstream = null;         string result = "";         try {              // create httpclient             httpclient httpclient = new defaulthttpclient();              // time functions before             calendar calendarbefore = calendar.getinstance();// instance class calendar             int millisecondsbefore = calendarbefore.get(calendar.millisecond);              // make request given url             httpresponse httpresponse = httpclient.execute(new httpget(url));              // time functions after             calendar calendarafter = calendar.getinstance();// instance class calendar             int millisecondsafter = calendarafter.get(calendar.millisecond);              // time difference calculation             int timediff = millisecondsafter - millisecondsbefore;              string timedifference = new string(); // time difference (after-before)              //verify signal of timedifference value             if(timediff < 0){                 timediff = timediff * (-1); // reverse signal in operation                 timedifference=integer.tostring(timediff);             }             else{                 timedifference=integer.tostring(timediff);                               }               // receive response inputstream             inputstream = httpresponse.getentity().getcontent();              // convert input stream string              if(inputstream != null)                 result = convertinputstreamtostring(inputstream, timediff);             else                 result = "did not work!";          } catch (exception e) {             log.d("inputstream", e.getlocalizedmessage());         }          return result;     } 

so, i'm measuring lot of things don't need. need measure time takes receive pdu's.

if guys know can me, me lot. if have other suggestion, love hear.

thank you!

may can help:

public static string get(string url){         inputstream inputstream = null;         string result = "";         try {               // create httpclient             httpclient httpclient = new defaulthttpclient();             //get bytes of data consumed            long oldcount = android.net.trafficstats.getmobilerxbytes();              // make request given url             httpresponse httpresponse = httpclient.execute(new httpget(url));               //get bytes of data consumed              long newcount = android.net.trafficstats.getmobilerxbytes();              //gettotaldata consumed             log.i("totaldataconsumption",(newcount-oldcount)+" bytes");              // receive response inputstream             inputstream = httpresponse.getentity().getcontent();              // convert input stream string             if(inputstream != null)                 result = convertinputstreamtostring(inputstream, timediff);             else                 result = "did not work!";          } catch (exception e) {             log.d("inputstream", e.getlocalizedmessage());         }          return result;     } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -