1 /*---------------------------
3 * Created on Jul 18, 2007
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
;
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
) {
27 System
.out
.println("communicating with server=" + client
);
28 in
= new DataInputStream(client
.getInputStream());
29 out
= new PrintStream(client
.getOutputStream());
30 } catch (IOException e
) {
33 } catch (IOException e2
) { ; }
34 System
.err
.println("Exception while opening socket streams: " + e
);
40 * @see java.lang.Runnable#run()
46 BufferedReader bufReader
= new BufferedReader(new InputStreamReader(in
));
48 // read in a line from the client
49 line
= bufReader
.readLine();
52 // and write out the reversed line
53 System
.out
.println("[server/" + line
.length() + "]" + line
);
54 if (line
.length() == 0)
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");
67 buf
.append("" + new Date() + " / " + this.client
);
68 buf
.append("</body>");
69 buf
.append("</html>");
71 } catch (IOException e
) {
75 if (out
!= null) out
.close();
76 if (in
!= null) in
.close();
78 } catch (IOException e2
) {;}
79 System
.out
.println("[server] closing connection");
80 } // End of Try - Catch - Finally