final ServerSocket accept = serverSocket;
Thread thread = new Thread() {
public void run() {
try {
System.out.println("server accepting");
Socket s = accept.accept();
Thread.sleep(100);
System.out.println("server accepted:" + s);
System.out.println("server read:" + s.getInputStream().read());
Thread.sleep(200);
s.getOutputStream().write(234);
Thread.sleep(100);
System.out.println("server closing");
s.close();
System.out.println("server done");
} catch (Throwable t) {
t.printStackTrace();
}
}
};
thread.start();
Thread.sleep(1000);
Socket socket = new Socket();
socket.setSoTimeout(2000);
InetSocketAddress socketAddress = new InetSocketAddress(address, port);
System.out.println("client:" + socketAddress);
try {
socket.connect(socketAddress, 2000);
Thread.sleep(200);
System.out.println("client:" + socket.toString());
socket.getOutputStream().write(123);
Thread.sleep(100);
System.out.println("client read:" + socket.getInputStream().read());
socket.close();
} catch (Throwable t) {
t.printStackTrace();
}
thread.join(5000);
if (thread.isAlive()) {