Upload and Download rate profiling in Android [closed]

扶醉桌前 提交于 2019-12-05 06:23:12

You need to download a considerably large file, something that takes atleast 15 seconds to download. The bigger the file, the better result you would receive. Use an always-on server with high availability. Also, use accumulation on the time of your network calls only (I believe that you must be using some socket to read in a while loop. So do System.currentTimeMillis() before and after socket.read() and keep adding them)

This is pretty much what SpeedTest.net does as well

As far as upload is concerned, you can do the same thing. A rough pseudo code :

upload (String remote, InputStream localfile){
     Socket s = openDataConnection(remote);
     OutputStream os = new BufferedOutputStream (s.getOutputStream(), MAX_BUFFER_SIZE);

     byte[] buffer = new byte[MAX_BUFFER_SIZE];
     long totalTime = 0L;
     while((buffer = localfile.read())!= -1){
         long startTime = System.currentTimeMillis();
         os.write(buffer);
         long endTime = System.currentTimeMillis();
         totalTime += (endTime - startTime);
     }
}

To do the uploads, you will need to set up a two-way communication with the server. I would do it with a simple loop:

while(x){
Starttime =getCurrentTime()
Sendfile() //Send a Xmb file that the server can verify
waitForVerification() // Wait for a reply from server.
compareCurrentTimeWithStartingTime() // compare the times.
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!