我正在计算网络吞吐量
吞吐量=总数据包(接收)/总时间消耗。
我已经用服务器创建了一个专用套接字并上传和下载文件。我得到的输出不符合标记代码如下:
public void uploadTest() throws Exception
{
byte[] arrayOfByte = new byte[BUF_SIZE];
Utility.debugMessage(getName()+" uploadTest getLocalAddress() = "+ mUploadSocket.getLocalAddress()+" getLocalPort() = "+ mUploadSocket.getLocalPort()+" isBound() = "+mUploadSocket.isBound()+" isConnected() = "+ mUploadSocket.isConnected());
DataOutputStream localDataOutputStream = new DataOutputStream(mUploadSocket.getOutputStream());
sendMessage(Constants.MSG_CONN_LATENCY,(int)initiatingConnectionTime/* (System.currentTimeMillis()-initiatingConnectionTime)*/,-1,null);
String uploadFilePath=null;
uploadFilePath= Utility.createFileOnSdCard(testCaseDetails.getFileSize());
int totalCycle=testCaseDetails.getCycle();
double allCycleThroughPut=0;
Utility.debugMessage(getName()+" uploadTest ToTal Available bytes","localDataInputStream.available() :: "+localDataOutputStream.size());
for(int i=1;i<=totalCycle;i++)
{
long totalTime=0L;`enter code here`
long updateDelta=0;
long bytesRead=0L;
long totalReceived=0L;
File testFile = new File(uploadFilePath);
fileSize=testFile.length();
FileInputStream fis = new FileInputStream(testFile);
BufferedInputStream bis = new BufferedInputStream(fis);
while((bytesRead=bis.read(arrayOfByte))>Constants.NO_DATA)
{
long currentTime=System.currentTimeMillis();
localDataOutputStream.write(arrayOfByte,0,(int)bytesRead);
totalReceived+=bytesRead;
int progress=(int)((totalReceived/(double)fileSize)*100);
Utility.debugMessage(NAME+" uploadTest Downloading "," progress = "+progress+"totalSend = "+totalReceived);
updateDelta =System.currentTimeMillis() - currentTime;
if(sendYUpdate)
{//Check y axis max value
sendMessage(Constants.MSG_UPDATE_Y_AXIS_LIMIT,(int)(Utility.calculate(updateDelta, bytesRead).getKilobits()),-1, null);
if(skipCounter==0)
{
sendYUpdate=false;
}
else
{
skipCounter--;
}
}
else
{
sendMessage(Constants.MSG_UPDATE_STATUS,progress,(int) totalReceived, Utility.calculate(updateDelta, bytesRead));
}
totalTime+=updateDelta;
}
bis.close();
long downloadTime=totalTime;
SpeedInfo currentAverageThrougput=Utility.calculate(downloadTime, totalReceived);
allCycleThroughPut+=currentAverageThrougput.getKilobits();
sendMessage(Constants.MSG_CYCLE_STATUS, -1,i,currentAverageThrougput );
sendYUpdate=true;
}
localDataOutputStream.close();
sendMessage(Constants.MSG_COMPLETE_STATUS,(int)(allCycleThroughPut/totalCycle),-1,null);
if(!Constants.RUN_ON_LOCAL)
{
try {
Utility.closeSocket( con,Utility.getSharePrefValue(con, Constants.SERVER_BASE_URL)+"/TestMetrico/metrico/closeConnection",Integer.parseInt(Utility.getSharePrefValue(con, Constants.SOCKET_SERVER_PORT)));
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
public void downloadTest() throws IOException
{
int totalCycle=testCaseDetails.getCycle();
double allCycleThroughPut=0;
for(int i=1;i<=totalCycle;i++)
{
byte[] arrayOfByte = new byte[BUF_SIZE];
if(mDownloadSocket.isClosed())
{
mDownloadSocket=null;
mDownloadSocket=new Socket();
connectDownload();
}
Utility.debugMessage(NAME+" downloadTest Start Downloading LocalAddress = "+ mDownloadSocket.getLocalAddress()+" getLocalPort = "+mDownloadSocket.getLocalPort()+" isBound = "+mDownloadSocket.isBound()+" isConnected = "+mDownloadSocket.isConnected());
DataInputStream localDataInputStream = new DataInputStream(mDownloadSocket.getInputStream());
sendMessage(Constants.MSG_CONN_LATENCY,(int) initiatingConnectionTime /*(System.currentTimeMillis()-initiatingConnectionTime)*/,Constants.PARAMETER_NOT_USED,null);
Utility.debugMessage(NAME+" downloadTest ToTal Available bytes","localDataInputStream.available() :: "+localDataInputStream.available());
float updateDelta=0;
long received=0L;
long totalTime=0L;
long totalReceived=0L;
long currentTime=System.currentTimeMillis();
while (( received=localDataInputStream.read(arrayOfByte)) > Constants.NO_DATA)
{
totalReceived+=received;
int progress=(int)((totalReceived/(double)1048576)*100);
updateDelta = System.currentTimeMillis()-currentTime;
Utility.debugMessage(NAME+" downloadTest Downloading buffer", "Received bytes= "+received+"totalReceived bytes= "+totalReceived+"updateDelta time = "+updateDelta);
if(sendYUpdate)
{//Check y axis max value
sendMessage(Constants.MSG_UPDATE_Y_AXIS_LIMIT,(int)( Utility.calculate(updateDelta, received).getKilobits()),-1, null);
if(skipCounter==0)
{
sendYUpdate=false;
}
else
{
skipCounter--;
}
}
else
{
sendMessage(Constants.MSG_UPDATE_STATUS,progress,(int) totalReceived, Utility.calculate(updateDelta, received));
}
totalTime+=updateDelta;
currentTime=System.currentTimeMillis();
}
long downloadTime=totalTime;//(totalTime-start);
SpeedInfo currentAverageThrougput=Utility.calculate(downloadTime, totalReceived);
allCycleThroughPut+=currentAverageThrougput.getKilobits();
sendMessage(Constants.MSG_CYCLE_STATUS, -1,i,currentAverageThrougput );
sendYUpdate=true;
localDataInputStream.close();
mDownloadSocket.close();
}
sendMessage(Constants.MSG_COMPLETE_STATUS,(int)(allCycleThroughPut/totalCycle),-1,null);
if(!Constants.RUN_ON_LOCAL)
{
try {
Utility.closeSocket( con,Utility.getSharePrefValue(con, Constants.SERVER_BASE_URL)+"/TestMetrico/metrico/closeConnection",Integer.parseInt(Utility.getSharePrefValue(con, Constants.SOCKET_SERVER_PORT)));
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
public static SpeedInfo calculate(final float downloadTime,
final float bytesIn) {
SpeedInfo info = new SpeedInfo();
float downloadTimeTemp = downloadTime;
// if(downloadTimeTemp==0) downloadTimeTemp=1;
// from mil to sec
// TimeUnit.MILLISECONDS.toSeconds(downloadTime)
long bytespersecond = (long) (bytesIn / downloadTimeTemp) * 1000;
double kilobits = bytespersecond * Constants.BYTE_TO_KILOBIT;
double kilobytes = bytespersecond * Constants.BYTE_TO_KILOBYTE;// Constants.BYTE_TO_KILOBIT;
//double megabits = kilobits * Constants.KILOBIT_TO_MEGABIT;
double megabits = bytespersecond*0.000000953674;
info.setDownspeed(bytespersecond);
info.setKilobits(kilobits);
info.setMegabits(megabits);
TotalKB += kilobits;
TotalTime += downloadTime;
Utility.debugMessage(" downloadTest time in Downloading buffer",
"bytespersecond = " + bytespersecond);
Utility.debugMessage(" downloadTest time in Downloading buffer",
"kilobits = " + kilobits);
Utility.debugMessage(" Total downloadTest time in Downloading buffer TotalKB = "
+ TotalKB + " , TotalTime = " + TotalTime);
return info;
}
public static final double EDGE_THRESHOLD = 176.0;
public static final double BYTE_TO_KILOBIT = 0.0078125;
public static final double KILOBIT_TO_MEGABIT = 0.0009765625;
public static final double BYTE_TO_KILOBYTE=0.000976562;
如果有什么问题,请告诉我:
300Mbps WIFI 路由器我得到enter code here
75Mbps 上传和 500 到 750 Mbps 下载速度
我正在我的机器上运行服务器并通过 LAN 上的 300Mbps 路由器访问它?