【发布时间】:2012-06-16 08:34:20
【问题描述】:
我想查找设备网络上传速度和延迟,我尝试了 FTP 文件上传但没有成功。有人可以帮我确定网络上传速度吗?
【问题讨论】:
标签: android file-upload network-programming
我想查找设备网络上传速度和延迟,我尝试了 FTP 文件上传但没有成功。有人可以帮我确定网络上传速度吗?
【问题讨论】:
标签: android file-upload network-programming
获取当前网络连接类型:
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
int networkType = telephonyManager.getNetworkType();
以及延迟:
String host = "172.16.0.2";
int timeOut = 3000;
long[] time = new long[5];
Boolean reachable;
for(int i = 0; i < 5; i++)
{
long BeforeTime = System.currentTimeMillis();
reachable = InetAddress.getByName(host).isReachable(timeOut);
long AfterTime = System.currentTimeMillis();
Long TimeDifference = AfterTime - BeforeTime;
time[i] = TimeDifference;
}
【讨论】:
我关注this link 并获得了几乎正确的下载速度。为了提高上传速度,我创建了一个 PHP api,将其上传到 FTP 服务器并从设备调用它并上传一个文件。然后我计算上传前和上传后的时间得到上传速度。
【讨论】: