提交 6472e58b authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved testNetwork

上级 e2ebe701
...@@ -687,7 +687,9 @@ public class Build extends BuildBase { ...@@ -687,7 +687,9 @@ public class Build extends BuildBase {
*/ */
public void testNetwork() { public void testNetwork() {
try { try {
System.out.println("localhost:" + InetAddress.getByName("localhost")); long start = System.currentTimeMillis();
System.out.println("localhost:");
System.out.println(" " + InetAddress.getByName("localhost"));
for (InetAddress address : InetAddress.getAllByName("localhost")) { for (InetAddress address : InetAddress.getAllByName("localhost")) {
System.out.println(" " + address); System.out.println(" " + address);
} }
...@@ -708,6 +710,7 @@ public class Build extends BuildBase { ...@@ -708,6 +710,7 @@ public class Build extends BuildBase {
System.out.println(serverSocket); System.out.println(serverSocket);
int port = serverSocket.getLocalPort(); int port = serverSocket.getLocalPort();
final ServerSocket accept = serverSocket; final ServerSocket accept = serverSocket;
start = System.currentTimeMillis();
Thread thread = new Thread() { Thread thread = new Thread() {
public void run() { public void run() {
try { try {
...@@ -728,7 +731,9 @@ public class Build extends BuildBase { ...@@ -728,7 +731,9 @@ public class Build extends BuildBase {
} }
}; };
thread.start(); thread.start();
System.out.println("time: " + (System.currentTimeMillis() - start));
Thread.sleep(1000); Thread.sleep(1000);
start = System.currentTimeMillis();
final Socket socket = new Socket(); final Socket socket = new Socket();
socket.setSoTimeout(2000); socket.setSoTimeout(2000);
final InetSocketAddress socketAddress = new InetSocketAddress(address, port); final InetSocketAddress socketAddress = new InetSocketAddress(address, port);
...@@ -750,16 +755,21 @@ public class Build extends BuildBase { ...@@ -750,16 +755,21 @@ public class Build extends BuildBase {
System.out.println("not connected, trying localhost:" + socketAddress); System.out.println("not connected, trying localhost:" + socketAddress);
socket.connect(localhostAddress, 2000); socket.connect(localhostAddress, 2000);
} }
System.out.println("time: " + (System.currentTimeMillis() - start));
Thread.sleep(200); Thread.sleep(200);
start = System.currentTimeMillis();
System.out.println("client:" + socket.toString()); System.out.println("client:" + socket.toString());
socket.getOutputStream().write(123); socket.getOutputStream().write(123);
System.out.println("time: " + (System.currentTimeMillis() - start));
Thread.sleep(100); Thread.sleep(100);
start = System.currentTimeMillis();
System.out.println("client read:" + socket.getInputStream().read()); System.out.println("client read:" + socket.getInputStream().read());
socket.close(); socket.close();
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }
thread.join(5000); thread.join(5000);
System.out.println("time: " + (System.currentTimeMillis() - start));
if (thread.isAlive()) { if (thread.isAlive()) {
System.out.println("thread is still alive, interrupting"); System.out.println("thread is still alive, interrupting");
thread.interrupt(); thread.interrupt();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论