import java.net.*; import java.io.*; public class Server { static int round = 1; static int msgnum = 5000; static long start = 0; static long end = 0; static int overhead = 0; static ServerSocket serverSocket = null; public static void main(String[] args) throws IOException { if (args.length != 1 ) return; msgnum = Integer.parseInt(args[0]); // round = Integer.parseInt(args[1]); try { serverSocket = new ServerSocket(4444); } catch (IOException e) { System.err.println("Could not listen on port: 4444."); System.exit(1); } // int i = 0; // while(i++ < round) test(); System.out.println("Average Time:" + overhead/round + " milliseconds"); serverSocket.close(); } private static void test() throws IOException{ System.err.println("test start"); Socket clientSocket = null; try { clientSocket = serverSocket.accept(); } catch (IOException e) { System.err.println("Accept failed."); System.exit(1); } DataInputStream in = new DataInputStream(clientSocket.getInputStream()); String inputLine; int msgcount = 0; while ((inputLine=in.readLine()) != null){ msgcount ++; if(msgcount == 1) start = System.currentTimeMillis(); if (msgcount == msgnum) break; } end = System.currentTimeMillis(); overhead += (end - start); in.close(); clientSocket.close(); } }