|
|
|
|
@ -9,6 +9,7 @@ import seng302.Networking.Utils.*;
|
|
|
|
|
import javax.xml.parsers.ParserConfigurationException;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.net.*;
|
|
|
|
|
import java.nio.Buffer;
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
|
import java.nio.ByteOrder;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
@ -50,11 +51,13 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
|
|
|
|
|
private RaceStartStatus raceStartStatus;
|
|
|
|
|
|
|
|
|
|
private BufferedInputStream inStream;
|
|
|
|
|
|
|
|
|
|
public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{
|
|
|
|
|
|
|
|
|
|
this.connectionSocket = socket;
|
|
|
|
|
// this.connectionSocket = new Socket("livedata.americascup.com",4941);
|
|
|
|
|
|
|
|
|
|
this.inStream = new BufferedInputStream(connectionSocket.getInputStream());
|
|
|
|
|
this.course = course;
|
|
|
|
|
this.boatLocation = new HashMap<>();
|
|
|
|
|
this.boatStatus = new HashMap<>();
|
|
|
|
|
@ -143,11 +146,11 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
/**
|
|
|
|
|
* Takes an inputStream and reads the first 15 bytes (the header) and gets the message length
|
|
|
|
|
* for the whole message then reads that and returns the byte array
|
|
|
|
|
* @param inStream inputStream from socket
|
|
|
|
|
* @return encoded binary messsage bytes
|
|
|
|
|
* @throws IOException made by the inputstream reading
|
|
|
|
|
*/
|
|
|
|
|
private static byte[] getBytes(InputStream inStream) throws IOException {
|
|
|
|
|
private byte[] getBytes() throws IOException {
|
|
|
|
|
inStream.mark(0);
|
|
|
|
|
if (inStream.available() < 15) return null;//if there is not enough bytes foer the headerr
|
|
|
|
|
byte[] headerBytes = new byte[15];
|
|
|
|
|
inStream.read(headerBytes);
|
|
|
|
|
@ -170,11 +173,8 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
//receiver loop that gets the input
|
|
|
|
|
boolean receiverLoop = true;
|
|
|
|
|
while(receiverLoop) {
|
|
|
|
|
//gets the input from the socket
|
|
|
|
|
InputStream inFromClient = connectionSocket.getInputStream();
|
|
|
|
|
|
|
|
|
|
//converts the input into a byte array that can be read by the decoder
|
|
|
|
|
byte[] binaryMessage = getBytes(inFromClient);
|
|
|
|
|
byte[] binaryMessage = getBytes();
|
|
|
|
|
//if there is no bytes read.
|
|
|
|
|
if (binaryMessage == null){
|
|
|
|
|
continue;
|
|
|
|
|
|