我有一个应用程序在1234端口上侦听Docker容器内的客户端连接。我可以连接到本地主机上的端口1234,但无法发送字节。
使用docker run -p 1234:1234名称启动容器。
public static void start() {
try {
if (isServerAvailable()) {
LOGGER.info("The host is available");
outputStream = clientSocket.getOutputStream();
String message = SampleMessageFactory.getMessage("PhilipsMessage1.txt");
LOGGER.info("Sending Message:{}", message);
// MLLP Wrapping
outputStream.write(new byte[] { 0x0B });
outputStream.write(message.getBytes(EncodingConstant.UTF8.getEncodingName()));
outputStream.write(new byte[] { 0x1C });
outputStream.write(new byte[] { 0x0D });
}
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
public static boolean isServerAvailable() {
boolean result = false;
for (;;) {
try {
clientSocket = new Socket("127.0.0.1", 1234);
result = true;
break;
} catch (IOException e) {
LOGGER.error("The Server is not accepting connections on port 1234");
}
}
return result;
}