diff --git a/src/main/java/Main/ProtocolMessage.java b/src/main/java/Main/ProtocolMessage.java index 47c68d1..2764e30 100644 --- a/src/main/java/Main/ProtocolMessage.java +++ b/src/main/java/Main/ProtocolMessage.java @@ -114,6 +114,17 @@ public class ProtocolMessage { totalBytesRead += bytesRead; } + int messageLength = charArrayToInt(this.raw); + while(totalBytesRead != 4 + messageLength){ + int bytesRead = reader.read(this.raw, totalBytesRead, messageLength - totalBytesRead); + if (bytesRead == -1) { + logger.log(Level.ERROR, "Invalid packet."); + return; + } else + totalBytesRead += bytesRead; + } + + deconstructPacket(this.raw); }