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);
}
}
}
任何帮助或分析工具都非常赞赏:)