adding all of botlist, initial add
[botlist.git] / botlistprojects / botspider / spider / lib / java / spider_remote / src / org / spirit / loadtest / LoadTestServerThread.java
blob81069f29e1b29e3837f9176b3a250eda51f5f892
1 /*---------------------------
2 * Berlin Brown
3 * Created on Jul 18, 2007
4 */
5 package org.spirit.loadtest;
7 import java.io.BufferedReader;
8 import java.io.DataInputStream;
9 import java.io.IOException;
10 import java.io.InputStreamReader;
11 import java.io.PrintStream;
12 import java.net.Socket;
13 import java.util.Date;
15 /**
16 * Simple Server Client Thread Handler
18 public class LoadTestServerThread implements Runnable {
19 private Socket client;
20 private boolean running = false;
21 private DataInputStream in;
22 private PrintStream out;
24 public LoadTestServerThread(Socket client) {
25 this.client = client;
26 try {
27 System.out.println("communicating with server=" + client);
28 in = new DataInputStream(client.getInputStream());
29 out = new PrintStream(client.getOutputStream());
30 } catch (IOException e) {
31 try {
32 client.close();
33 } catch (IOException e2) { ; }
34 System.err.println("Exception while opening socket streams: " + e);
35 return;
39 /**
40 * @see java.lang.Runnable#run()
42 public void run() {
43 running = true;
44 String line;
45 try {
46 BufferedReader bufReader = new BufferedReader(new InputStreamReader(in));
47 while(running) {
48 // read in a line from the client
49 line = bufReader.readLine();
50 if (line == null)
51 break;
52 // and write out the reversed line
53 System.out.println("[server/" + line.length() + "]" + line);
54 if (line.length() == 0)
55 break;
57 // Write a html response back
58 StringBuffer buf = new StringBuffer();
59 buf.append("HTTP/1.1 200 Ok\r\n");
60 buf.append("Server: Apache-Test\r\n");
61 buf.append("Connection: close\r\n");
62 buf.append("Content-Type: text/html\r\n");
63 buf.append("\r\n");
65 buf.append("<html>");
66 buf.append("<body>");
67 buf.append("" + new Date() + " / " + this.client);
68 buf.append("</body>");
69 buf.append("</html>");
70 out.println(buf);
71 } catch (IOException e) {
72 e.printStackTrace();
73 } finally {
74 try {
75 if (out != null) out.close();
76 if (in != null) in.close();
77 client.close();
78 } catch (IOException e2) {;}
79 System.out.println("[server] closing connection");
80 } // End of Try - Catch - Finally
84 // End of File