import java.io.*; import java.net.*; import java.util.*; public class HttpKeepAliveClient extends Thread { static String host=""; static int port ; static String url=""; static int threads=1; static int hitcount=0; static boolean timeout=false; public static void main(String[] args) { try{ host=args[0]; port=Integer.parseInt(args[1]); url=args[2]; threads = Integer.parseInt(args[3]); if(System.getProperty("hitcount") != null ) hitcount=Integer.parseInt(System.getProperty("hitcount")); if(System.getProperty("timeout") != null ) timeout=Boolean.parseBoolean(System.getProperty("timeout")); HttpKeepAliveClient client[] = new HttpKeepAliveClient[threads]; for(int i=1;i<=threads;i++){ client[i-1] = new HttpKeepAliveClient(); System.out.println("Starting client :"+i); client[i-1].start(); } boolean isalive; for(int i=1;i<=threads;i++){ isalive=true; while(isalive){ if(client[i-1].isAlive()) Thread.sleep(100); else isalive=false; } } } catch(Exception e){e.printStackTrace();} } public void run(){ try{ Socket sock = new Socket(host, port); OutputStream os = sock.getOutputStream(); InputStream is = sock.getInputStream(); BufferedReader bis = new BufferedReader(new InputStreamReader(is)); ReaderThread read[]; if(hitcount != 0){ read=new ReaderThread[hitcount]; for(int num=1;num<=hitcount;num++){ if(num!=hitcount || timeout){ sendRequest(os, url,"Connection: keep-alive"); Thread.sleep(3000); } else{ sendRequest(os, url,"Connection: close"); Thread.sleep(3000); } read[num-1]=new ReaderThread(bis); read[num-1].start(); } boolean isalive; for(int i=0;i