我正在向 TCP 服务器发送一条消息,并且在运行它之后,java.net.BindException: Address already in use
当我再次尝试运行它时遇到错误。我认为套接字将是未绑定的;不过,我在文档中找不到任何具体说明它的内容。我如何释放端口,我在这里没有正确结束交易吗?这是我的客户:
public class TcpPingClient {
public static void main(String[] args) throws Exception {
Socket tcpSocket = new Socket();
tcpSocket.bind(new InetSocketAddress("192.168.1.2", 45030));
tcpSocket.connect(new InetSocketAddress("192.168.1.2", 1211));
DataOutputStream out = new DataOutputStream(tcpSocket.getOutputStream());
out.writeBytes("oh hey\n");
tcpSocket.close();
}
}