You are on page 1of 10

The Bandwidth test project the files client.java and server.

java were created to measure the bandwidth in units of time (bytes per Millisecond) by sending and receiving multiple byte packets that increased in size in a Ping-Pong fashion between two machines. An specific machine could be designated as the receiving machine involved in the testing process could by entering its specific IP address at run time. The results of the test were then put in graph form to demonstrate the difference in the theoretical expectations of bandwidth and the actual real life achievable bandwidth. As seen in the spike created at 1024 Bytes in the graph it is more efficient to send larger packets in each unit of time.
Byte size theoritical machine model model 1 3.72E-05 5.01E-07 2 3.92E-05 5.43E-07 4 3.72E-05 6.29E-07 8 3.77E-05 8.00E-07 16 3.92E-05 1.14E-06 32 4.20E-05 1.82E-06 64 4.78E-05 3.19E-06 128 5.87E-05 5.92E-06 256 8.17E-05 1.14E-05 512 1.26E-04 2.23E-05 1024 2.16E-04 4.42E-05 2048 8.74E-05 8.79E-05 4096 1.76E-04 1.75E-04 8192 3.50E-04 3.50E-04 16384 7.01E-04 7.00E-04 32768 1.40E-03 1.40E-03 size Theoritical machine Bandwidth Bandwidth Index 1 2.69E+04 2.00E+06 2 5.10E+04 3.68E+06 4 1.08E+05 6.36E+06 8 2.12E+05 1.00E+07 16 4.08E+05 1.40E+07 32 7.62E+05 1.76E+07 64 1.34E+06 2.01E+07 128 2.18E+06 2.16E+07 256 3.13E+06 2.25E+07 512 4.06E+06 2.30E+07 1024 4.74E+06 2.32E+07 2048 2.34E+07 2.33E+07 4096 2.33E+07 2.34E+07 8192 2.34E+07 2.34E+07 16384 2.34E+07 2.34E+07 32768 2.34E+07 2.34E+07

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

machine Bandw idth 2.50E+07

Theoritical Bandw idth

2.00E+07

1.50E+07

1.00E+07

5.00E+06

0.00E+00 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
B yte Size

Client.java source code import java.io.*; import java.net.*; import java.text.*; public class server { public static void main(String []args) { int size = 32768; //last size for byte buff to be sent int repeat= 1000; //used in a loop to repeat sending byte[] buff; //holds bytes in wanted sizes double time=0; //to hold the oneway time long starttime = 0, stoptime = 0; double MegaBitsPerSec=0; //holds bandwidth in megabits/sec double BytesPerMiliSec=0; //holds bandwidth in bytes/milisec double MegaBits= 0; //holds calculate value for bytes to megabits double MilisecToSecond=0; //holds calculate value for milisecs to seconds try { // Create a socket on server ServerSocket ss = new ServerSocket(5555); // --------------------------------------------------------------// Now start accepting connections from clients in a while loop // The server should run in an infinite loop while(true) { Socket socket = ss.accept(); // accept connection from client System.out.println("A new client is connected.");

// to get data to and from server InputStream in = socket.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); OutputStream out = socket.getOutputStream(); PrintWriter pr = new PrintWriter(out, true); String strAnother=""; while(!strAnother.equals("d")) { strAnother = br.readLine(); // read option System.out.println("User option is " + strAnother); switch(strAnother.charAt(0)) { case 'd': System.out.println("Request for disconnect."); break; case 'z': System.out.println("\nBytes\t\tMilli\t\tBytes\t\t"/*MegaBits*/); System.out.println("\t\tsecond\t\t/Millisec\t"/*/Second\n*/); /*the each time the loop goes around the value of len is doubled *therefore immitating 1,2,4....32768, and as it goes around it *creates the same size of array buff []byte,the byte is sent and *recieved 1000 times so the time can be detected in millisecs. */ for(int len=1;len<=size;len *=2){ buff = new byte [len]; starttime=System.currentTimeMillis();

for (int i=0;i<repeat;i++) { in.read(buff); //send bytes out.write(buff); //recieve bytes } stoptime=System.currentTimeMillis(); /*divide time by 2 to calculate oneway transmission *divide by 1000 which is used in the delay process*/ time=(double)(stoptime-starttime)/2/1000; BytesPerMiliSec=(len/time); //calculate bandwidth Bytes/milisecs MegaBits=(len*8)/1000000; //calculate megabits byte*8bits/1 megabit MilisecToSecond=time/1000; //convert millisec to second MegaBitsPerSec=MegaBits/MilisecToSecond; //bandwidth in form of mehabits/sec /*change the decimal format of the calculations *because the bandwidth in Megabits/sec is too small *it shows up as zeros when the program runs, *so i have commented it out,so it doesnt print*/ NumberFormat number = NumberFormat.getNumberInstance(); if(number instanceof DecimalFormat) { DecimalFormat decimal = (DecimalFormat) number; decimal.applyPattern("0.##E0"); String s1 = decimal.format(time); String s2 = decimal.format(BytesPerMiliSec); //String s3 = decimal.format(MegaBitsPerSec); System.out.println(len+"\t\t"+s1+"\t\t"+s2+"\t\t"/*+s3*/);

} } } break; } // End of switch // End of while// create a thread to allow simultaneous connections // End of while }} // End of try catch(Exception e) { System.out.println("Some kind of error has occurred."); } // End of exception } } // End of main() // End of class

Server.java source code import java.io.*; import java.net.*; import java.text.*; public class server { public static void main(String []args) { int size = 32768; //last size for byte buff to be sent int repeat= 1000; //used in a loop to repeat sending byte[] buff; //holds bytes in wanted sizes double time=0; //to hold the oneway time long starttime = 0, stoptime = 0; double MegaBitsPerSec=0; //holds bandwidth in megabits/sec double BytesPerMiliSec=0; //holds bandwidth in bytes/milisec double MegaBits= 0; //holds calculate value for bytes to megabits double MilisecToSecond=0; //holds calculate value for milisecs to seconds try { // Create a socket on server ServerSocket ss = new ServerSocket(5555); // --------------------------------------------------------------// Now start accepting connections from clients in a while loop // The server should run in an infinite loop while(true) { Socket socket = ss.accept(); // accept connection from client System.out.println("A new client is connected.");

// to get data to and from server InputStream in = socket.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); OutputStream out = socket.getOutputStream(); PrintWriter pr = new PrintWriter(out, true); String strAnother=""; while(!strAnother.equals("d")) { strAnother = br.readLine(); // read option System.out.println("User option is " + strAnother); switch(strAnother.charAt(0)) { case 'd': System.out.println("Request for disconnect."); break; case 'z': System.out.println("\nBytes\t\tMilli\t\tBytes\t\t"/*MegaBits*/); System.out.println("\t\tsecond\t\t/Millisec\t"/*/Second\n*/); /*the each time the loop goes around the value of len is doubled *therefore immitating 1,2,4....32768, and as it goes around it *creates the same size of array buff []byte,the byte is sent and *recieved 1000 times so the time can be detected in millisecs. */ for(int len=1;len<=size;len *=2){ buff = new byte [len]; starttime=System.currentTimeMillis();

for (int i=0;i<repeat;i++) { in.read(buff); //send bytes out.write(buff); //recieve bytes } stoptime=System.currentTimeMillis(); /*divide time by 2 to calculate oneway transmission *divide by 1000 which is used in the delay process*/ time=(double)(stoptime-starttime)/2/1000; BytesPerMiliSec=(len/time); //calculate bandwidth Bytes/milisecs MegaBits=(len*8)/1000000; //calculate megabits byte*8bits/1 megabit MilisecToSecond=time/1000; //convert millisec to second MegaBitsPerSec=MegaBits/MilisecToSecond; //bandwidth in form of mehabits/sec /*change the decimal format of the calculations *because the bandwidth in Megabits/sec is too small *it shows up as zeros when the program runs, *so i have commented it out,so it doesnt print*/ NumberFormat number = NumberFormat.getNumberInstance(); if(number instanceof DecimalFormat) { DecimalFormat decimal = (DecimalFormat) number; decimal.applyPattern("0.##E0"); String s1 = decimal.format(time); String s2 = decimal.format(BytesPerMiliSec); //String s3 = decimal.format(MegaBitsPerSec); System.out.println(len+"\t\t"+s1+"\t\t"+s2+"\t\t"/*+s3*/);

} } } break; } // End of switch // End of while// create a thread to allow simultaneous connections // End of while }} // End of try catch(Exception e) { System.out.println("Some kind of error has occurred."); } // End of exception } } // End of main() // End of class