0
嗨java.net.ConnectException/java.net.ConnectException我試圖發送一個二進制信息到服務器的IP和端口:取決於正常運行或調試模式
192.168.2.101:10001
每50封郵件重新打開一次套接字。
如果我正常運行應用程序,我會在第5行中得到一個java.net.ConnectException,儘管我可以ping和telnet服務器。
如果我調試應用程序,我得到一個java.net.SocketException在不同的行(11),有時第一條消息似乎通過沒有任何錯誤。
private void sendMessage(String message, int relaisId, long timestamp) {
try {
if (connCount > 50) {
s = new Socket(ip, port); //RUN NORMALLY: java.net.ConnectException: Connection refused: connect
connCount=0;
}
outputStream = s.getOutputStream();
outputStream.write(message.getBytes());
outputStream.write(new byte[]{0});//DEBUG: java.net.SocketException: Connection reset by peer: socket write error
outputStream.flush();
connCount++;
} catch (UnknownHostException ex) {
logger.error("Host not found: " + ip + ":" + port, ex);
connCount=51;
retryMessage(message, relaisId, timestamp);// basically sleep 3s then call sendMessage
} catch (IOException ex) {
logger.error("Error at Relais No. " + relaisId + ": " + ip + ":" + port, ex);
connCount=51;
retryMessage(message, relaisId, timestamp); // basically sleep 3s then call sendMessage
} finally {
try {
if (connCount > 50 && s != null) {
s.close();
}
} catch (IOException ex) {
logger.error("IOException", ex);
}
}
}
任何幫助或分析工具都非常讚賞:)