Added connection screen to allow users to select available hosts from a preconfigured list.
- Added ConnectionController for initial client setup - Added RaceConnection class for socket data and checking - Configures StartController with a socket drawn from a host table #story[782]
This commit is contained in:
@@ -1,14 +1,53 @@
|
||||
package seng302;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 3/05/17.
|
||||
*/
|
||||
public class RaceConnection {
|
||||
private String hostname;
|
||||
private StringProperty hostname;
|
||||
private int port;
|
||||
private StringProperty status;
|
||||
|
||||
public RaceConnection(String hostname, int port) {
|
||||
this.hostname = hostname;
|
||||
this.hostname = new SimpleStringProperty(hostname);
|
||||
this.port = port;
|
||||
this.status = new SimpleStringProperty("");
|
||||
check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to create a socket to hostname and port, indicates status after test.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public boolean check() {
|
||||
try(Socket s = new Socket(hostname.get(), port)) {
|
||||
status.set("Ready");
|
||||
return true;
|
||||
} catch (IOException e) {}
|
||||
|
||||
status.set("Offline");
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname.get();
|
||||
}
|
||||
|
||||
public StringProperty hostnameProperty() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public StringProperty statusProperty() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user