diff --git a/src/main/java/rv/comm/rcssserver/ServerComm.java b/src/main/java/rv/comm/rcssserver/ServerComm.java index 48ba0f9..4297b01 100644 --- a/src/main/java/rv/comm/rcssserver/ServerComm.java +++ b/src/main/java/rv/comm/rcssserver/ServerComm.java @@ -152,8 +152,14 @@ private String readMessage() throws IOException // read from stream until all bytes in message are read byte[] buf = new byte[length]; int bytesRead = 0; - while (bytesRead < length) - bytesRead += in.read(buf, bytesRead, length - bytesRead); + while (bytesRead < length) { + int tmp = in.read(buf, bytesRead, length - bytesRead); + if (tmp < 0) { + // Unexpected EOF + return null; + } + bytesRead += tmp; + } return new String(buf); }