Java设置Client Socket链接Server超时时间
学习了:http://blog.csdn.net/tterminator/article/details/52494141
http://blog.csdn.net/fw0124/article/details/41227543
整理如下:
Socket client = null; // 创建一个流套接字,连接到指定主机上的指定端口号 // client = new Socket(IP, PORT); client = new Socket(); SocketAddress socketAddress = new InetSocketAddress(IP, PORT); int timeout = 10000; client.connect(socketAddress, timeout); client.setSoTimeout(timeout);
时间: 2024-10-14 00:43:13