#story[1087]main
parent
243c450790
commit
53a01402e1
@ -0,0 +1,46 @@
|
||||
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(){
|
||||
//TODO the connection needs to be moved to its own thread, so it doesn't block fx thread.
|
||||
InetSocketAddress i = new InetSocketAddress(hostname, port);
|
||||
try (Socket s = new Socket()){
|
||||
s.connect(i, 750);//TODO this should be at least a second or two, once moved to its own thread
|
||||
s.shutdownInput();
|
||||
s.shutdownOutput();
|
||||
s.close();
|
||||
rc.statusProperty().set("Ready");
|
||||
//System.out.println(String.valueOf(s.isClosed()));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
rc.statusProperty().set("Offline");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
pingPort();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue