From 444a4432c647a618196e3fe2f63e5aab33571900 Mon Sep 17 00:00:00 2001 From: Fan-Wu Yang Date: Mon, 1 May 2017 15:07:59 +1200 Subject: [PATCH] Fixed stream from messing up - Stream was getting code before all of it came therefore a while loop was added t owait for the code #story[782] #pair[hba56, fwy13] --- .../main/java/seng302/Networking/VisualiserInput.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/network/src/main/java/seng302/Networking/VisualiserInput.java b/network/src/main/java/seng302/Networking/VisualiserInput.java index 96b5a3ae..b538fc24 100644 --- a/network/src/main/java/seng302/Networking/VisualiserInput.java +++ b/network/src/main/java/seng302/Networking/VisualiserInput.java @@ -39,7 +39,8 @@ public class VisualiserInput implements Runnable public VisualiserInput(Socket connectionSocket) throws IOException{ - connectionSocket = new Socket(InetAddress.getLocalHost(), 4942); + //connectionSocket = new Socket(InetAddress.getLocalHost(), 4942); + this.connectionSocket = connectionSocket; this.course = new StreamedCourse(); this.boatLocation = new HashMap<>(); @@ -86,11 +87,14 @@ public class VisualiserInput implements Runnable */ private static byte[] getBytes(InputStream inStream) throws IOException { byte[] headerBytes = new byte[15]; - int i = inStream.read(headerBytes); + inStream.read(headerBytes); byte[] messageLenBytes = Arrays.copyOfRange(headerBytes, 13, 15); short messageLen = bytesToShort(messageLenBytes); byte[] messageBytesWithCRC = new byte[messageLen+4]; - int j = inStream.read(messageBytesWithCRC); + while (inStream.available() < messageLen + 4){ + //WE NEED THIS!!!! + } + inStream.read(messageBytesWithCRC, 0, messageLen + 4); ByteBuffer binaryMessageBytes = ByteBuffer.allocate(headerBytes.length+messageBytesWithCRC.length); binaryMessageBytes.put(headerBytes); binaryMessageBytes.put(messageBytesWithCRC);