You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.5 KiB
61 lines
1.5 KiB
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 cbt24 on 3/05/17.
|
|
*/
|
|
public class RaceConnection {
|
|
private final StringProperty hostname;
|
|
private final int port;
|
|
private final StringProperty status;
|
|
private final StringProperty gamename;
|
|
|
|
|
|
/**
|
|
* Constructor for remote host connections.
|
|
* @param hostname URL for remote host
|
|
* @param port port for game feed
|
|
*/
|
|
public RaceConnection(String hostname, int port, String gamename) {
|
|
this.hostname = new SimpleStringProperty(hostname);
|
|
this.port = port;
|
|
this.status = new SimpleStringProperty("");
|
|
check();
|
|
this.gamename = new SimpleStringProperty(gamename);
|
|
}
|
|
|
|
/**
|
|
* Tries to create a socket to hostname and port, indicates status after test.
|
|
* @return true if socket can connect
|
|
*/
|
|
public boolean check() {
|
|
Ping ping = new Ping(hostname.get(), port, this);
|
|
new Thread(ping).start();
|
|
return true;
|
|
}
|
|
|
|
public String getHostname() {
|
|
return hostname.get();
|
|
}
|
|
|
|
public StringProperty hostnameProperty() {
|
|
return hostname;
|
|
}
|
|
|
|
public int getPort() {
|
|
return port;
|
|
}
|
|
|
|
public StringProperty statusProperty() {
|
|
return status;
|
|
}
|
|
|
|
public StringProperty gamenameProperty() { return gamename;}
|
|
}
|