Merge remote-tracking branch 'origin/TCPDisconnection' into submission

main
fjc40 9 years ago
commit 020c0329b0

@ -87,6 +87,7 @@ public class RaceController extends Controller {
raceMap.setBoats(boats); raceMap.setBoats(boats);
raceMap.update(); raceMap.update();
raceBoundaries.draw(); raceBoundaries.draw();
//stop if the visualiser is no longer running
} }
/** /**

@ -4,6 +4,7 @@ import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
/** /**
@ -27,7 +28,9 @@ public class RaceConnection {
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public boolean check() { public boolean check() {
try(Socket s = new Socket(hostname.get(), port)) { InetSocketAddress i = new InetSocketAddress(hostname.get(), port);
try (Socket s = new Socket();){
s.connect(i, 5000);
status.set("Ready"); status.set("Ready");
return true; return true;
} catch (IOException e) {} } catch (IOException e) {}

@ -53,6 +53,8 @@ public class VisualiserInput implements Runnable
private BufferedInputStream inStream; private BufferedInputStream inStream;
private boolean receiverLoop = true;
public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{ public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{
this.connectionSocket = socket; this.connectionSocket = socket;
@ -63,7 +65,6 @@ public class VisualiserInput implements Runnable
this.boatStatus = new HashMap<>(); this.boatStatus = new HashMap<>();
this.markRounding = new HashMap<>(); this.markRounding = new HashMap<>();
//start Time //start Time
this.lastHeartbeatTime = System.currentTimeMillis(); this.lastHeartbeatTime = System.currentTimeMillis();
} }
@ -169,10 +170,16 @@ public class VisualiserInput implements Runnable
} }
public void run(){ public void run(){
this.receiverLoop = true;
try{ try{
//receiver loop that gets the input //receiver loop that gets the input
boolean receiverLoop = true;
while(receiverLoop) { while(receiverLoop) {
//if no heartbeat has been received in more than 6 seconds
//the connection will need to be restarted
if (timeSinceHeartbeat() > 6){
System.out.println("Connection has stopped, trying to reconnect");
receiverLoop = false;
}
//converts the input into a byte array that can be read by the decoder //converts the input into a byte array that can be read by the decoder
byte[] binaryMessage = getBytes(); byte[] binaryMessage = getBytes();
//if there is no bytes read. //if there is no bytes read.
@ -279,19 +286,16 @@ public class VisualiserInput implements Runnable
System.out.println("Broken Message!"); System.out.println("Broken Message!");
break; break;
} }
//if no heartbeat has been received in more than 6 seconds
//the connection will need to be restarted
if (timeSinceHeartbeat() > 6){
System.out.println("Connection has stopped, trying to reconnect");
receiverLoop = false;
}
} }
}catch(IOException e){ }catch(IOException e){
e.printStackTrace(); e.printStackTrace();
} }
} }
public boolean isReceiverLoop() {
return receiverLoop;
}
public static void main(String argv[]) throws Exception public static void main(String argv[]) throws Exception
{ {
Socket socket = new Socket("livedata.americascup.com", 4941); Socket socket = new Socket("livedata.americascup.com", 4941);

Loading…
Cancel
Save