From 50e7ece477a036d9737cb2f2e87f3d76693a0472 Mon Sep 17 00:00:00 2001 From: Kusal Ekanayake Date: Thu, 20 Apr 2017 19:17:12 +1200 Subject: [PATCH] Checking for the header of each packet as the stream parser checks for each byte to see if it matches with the desired header sequence. --- .../models/parsers/InputStreamParser.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/seng302/models/parsers/InputStreamParser.java b/src/main/java/seng302/models/parsers/InputStreamParser.java index 19005c1d..a086cf02 100644 --- a/src/main/java/seng302/models/parsers/InputStreamParser.java +++ b/src/main/java/seng302/models/parsers/InputStreamParser.java @@ -8,12 +8,16 @@ import java.net.Socket; public class InputStreamParser { - private static String currentLine; + //changed the currentline variable from sring to long in order to check it's value +// private static String currentLine; + private static long currentLine; private static BufferedReader buffer = null; private static void readLine() { try { - currentLine = buffer.readLine(); + //Rather than read strings it reads a long which is used for checking the head +// currentLine = buffer.readline(); + currentLine = buffer.read(); } catch (IOException e) { e.printStackTrace(); } @@ -42,10 +46,19 @@ public class InputStreamParser { readLine(); boolean reading = true; + long prev = 0; + long len = 0; while(reading) { - System.out.println(currentLine); +// System.out.println(currentLine); readLine(); - if (currentLine == null) { + //checking if it is the start of the packet + if(prev == 71 && currentLine == 65533) { + System.out.println("PACKET LENGTH: " + (len)); + len = 0; + } + len += 1; + prev = currentLine; + if (currentLine == -1) { reading = false; } }