2
我有一個Java servlet試圖連接到源(使用請求IP地址)。套接字超時在Servlet中不起作用
方法爲:
String ip = request.getRemoteAddr();
private void connect(String ip) throws SocketException, IOException {
Socket socket = new Socket();
socket.setSoTimeout(1000);
socket.connect(new InetSocketAddress(ip, Constant.PORT));
}
現在,如果它不連接withint第二它應該拋出異常,但它不是在一秒鐘內拋出異常,但需要一段時間像10-15秒。
有人可以幫助爲什麼會發生這種情況嗎?
感謝它的工作原理... – Makky