import library.net.*; import library.io.*; import java.io.IOException; public class KServer{ 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 != 2 ) 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("k 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; int len = 0; while ((inputLine=in.readLine()) != null){ msgcount ++; if(msgcount == 1){ System.out.println("message : " + inputLine + ", length:"+ inputLine.length() + "\n"); start = System.currentTimeMillis(); } len += inputLine.length(); if (msgcount == msgnum) break; } end = System.currentTimeMillis(); overhead += (end - start); in.close(); clientSocket.close(); System.out.println("received msg: "+ msgcount + ", size:"+ len + "\n"); } }