
Untitled
By: a guest on
Jul 10th, 2012 | syntax:
None | size: 1.16 KB | hits: 13 | expires: Never
public static void main(String args[]) throws IOException {
ExecutorService pool = Executors.newCachedThreadPool();
SocketStopwatch stopwatch = new SocketStopwatch(pool);
Socket s = new Socket();
stopwatch.doTimedOperation(s, new SocketStopwatch.SocketOperation() {
@Override
public void perform(Socket s) {
try {
long t1 = System.currentTimeMillis();
s.connect(new InetSocketAddress("hh.ru", 80));
System.out.println("connected");
PrintStream ps = new PrintStream(s.getOutputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
ps.print("GET / HTTP/1.0\r\n");
ps.print("\r\n");
ps.flush();
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
System.out.println();
System.out.println(System.currentTimeMillis() - t1);
System.out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
},
1000);
s.close();
pool.shutdown();
}