TCP connection at the front menu will no longer bug out if the socket is bugged.

- Timeout set on connection socket so that the socket will return false after 5 seconds.
#story[782]
main
Fan-Wu Yang 9 years ago
parent d52b09e74a
commit bdf215d0f1

@ -85,6 +85,7 @@ public class RaceController extends Controller {
raceMap.setBoats(boats);
raceMap.update();
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 java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
/**
@ -27,7 +28,9 @@ public class RaceConnection {
*/
@SuppressWarnings("unused")
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");
return true;
} catch (IOException e) {}

@ -53,6 +53,8 @@ public class VisualiserInput implements Runnable
private BufferedInputStream inStream;
private boolean receiverLoop = true;
public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{
this.connectionSocket = socket;
@ -63,7 +65,6 @@ public class VisualiserInput implements Runnable
this.boatStatus = new HashMap<>();
this.markRounding = new HashMap<>();
//start Time
this.lastHeartbeatTime = System.currentTimeMillis();
}
@ -169,10 +170,16 @@ public class VisualiserInput implements Runnable
}
public void run(){
this.receiverLoop = true;
try{
//receiver loop that gets the input
boolean receiverLoop = true;
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
byte[] binaryMessage = getBytes();
//if there is no bytes read.
@ -279,19 +286,16 @@ public class VisualiserInput implements Runnable
System.out.println("Broken Message!");
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){
e.printStackTrace();
}
}
public boolean isReceiverLoop() {
return receiverLoop;
}
public static void main(String argv[]) throws Exception
{
Socket socket = new Socket("livedata.americascup.com", 4941);

Loading…
Cancel
Save