Also got client-server handshake working. Multiple clients can connect and control their own boat. The client's boat has a larger black triangle drawn around it. Probably needs tidying up. Added isClientBoat boolean to VisualiserBoat. WindGenerator is now an interface, implemented by ConstantWindGenerator (useful for testing) and RandomWindGenerator. Added ConstantWindGeneratorTest. RandomWindGenerator was formerly WindGenerator. The WindGenerator is passed in to MockRace. CommandFactory throws a CommandConstructionException if it cannot create a command. MessageSerialiser and MessageDeserialiser correctly terminate on error. Readded VisualiserInput's switch statement in the main loop, pending a refactor. Removed the sleep statement from LobbyController - it was blocking javaFX thread. Lobby.fxml: moved buttons and text input into grid panes, so they don't break when you resize screen. Added some test object creation functions in several test classes (MockRaceTest.createMockRace(), BoatXMLReaderTest.createBoatDataSource(), etc...). #story[1095]
45 lines
1.0 KiB
Java
45 lines
1.0 KiB
Java
package visualiser.model;
|
|
|
|
import javafx.beans.property.SimpleStringProperty;
|
|
import javafx.beans.property.StringProperty;
|
|
|
|
import java.io.IOException;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.Socket;
|
|
|
|
/**
|
|
* Created by David on 26/07/2017.
|
|
*/
|
|
public class Ping implements Runnable {
|
|
|
|
private final String hostname;
|
|
private final int port;
|
|
private final RaceConnection rc;
|
|
|
|
public Ping(String hostname, int port, RaceConnection rc){
|
|
this.hostname = hostname;
|
|
this.port = port;
|
|
this.rc = rc;
|
|
}
|
|
|
|
public boolean pingPort() {
|
|
InetSocketAddress i = new InetSocketAddress(hostname, port);
|
|
try (Socket s = new Socket()){
|
|
s.connect(i, 1500);
|
|
s.shutdownInput();
|
|
s.shutdownOutput();
|
|
s.close();
|
|
rc.statusProperty().set("Ready");
|
|
return true;
|
|
} catch (IOException e) {
|
|
rc.statusProperty().set("Offline");
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
pingPort();
|
|
}
|
|
}
|