我试图阻止 TCP 端口在关闭后以 TIME_WAIT 状态等待,逻辑如下:
Socket sock = new Socket();
sock.setSoLinger(true, 0); // Set it as "0" before bind and connect.
sock.bind(new InetSocketAddress(clientAddress, clientPort));
sock.connect(new InetSocketAddress(serverAddress, serverPort), 8000);
// sock.close() will be called at the end.
之后我用 netstat 验证了这个端口在我的本地(Windows)和服务器端(RedHat Linux)没有在 TIME_WAIT 状态等待。但我仍然无法在不等待一段时间的情况下绑定到同一个 clientPort。
请注意,clientAddress 和 clientPort 取自公司 VPN(虚拟以太网适配器)。
我在这里错过了什么?