我创建了一个运行以下代码的新线程:
public static void startServer() throws IOException {
serverSocket = new ServerSocket(55000);
Socket clientSocket = serverSocket.accept();
}
The above code is run in a thread. Now, in my main class, I successfully create a socket connection to the server and I have checked it s integrity which is fine. here is the code:
Socket testServerSocket = new Socket("127.0.0.1", 55000);
assertEquals("/127.0.0.1", testServerSocket.getInetAddress().toString());
assertEquals(55000, testServerSocket.getPort());
This runs perfect. Then, again from my main, I kill the server connection that closes the connection on the server side. However the following code keeps failing: assertEquals(false, testServerSocket.isBound());
它不断回归真实。同样,如果我检查连接的远程IP地址,它不会返回null,而是返回/127.0.0.1。你知道为什么会发生这种情况吗?非常感谢你的帮助