Java client BECN implementation (#155)
This commit is contained in:
committed by
Jason Watkins
parent
90ccec0d07
commit
c018d6c3be
@@ -0,0 +1,35 @@
|
||||
package gov.nasa.xpc.ex;
|
||||
|
||||
import gov.nasa.xpc.XPlaneConnect;
|
||||
import gov.nasa.xpc.discovery.XPlaneConnectDiscovery;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
|
||||
|
||||
|
||||
public class DiscoveryConnectionExample {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
XPlaneConnectDiscovery discovery = new XPlaneConnectDiscovery();
|
||||
discovery.start(xpc -> {
|
||||
|
||||
sendDref(xpc);
|
||||
});
|
||||
System.out.println("Example done");
|
||||
}
|
||||
|
||||
static void sendDref(XPlaneConnect xpc) {
|
||||
System.out.println("Sending DREF");
|
||||
try {
|
||||
xpc.getDREF("sim/test/test_float");
|
||||
|
||||
} catch (SocketException e) {
|
||||
System.out.println("Unable to set up the connection. (Error message was '" + e.getMessage() + "'.)");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Something went wrong with one of the commands. (Error message was '" + e.getMessage() + "'.)");
|
||||
}
|
||||
System.out.println("Sending DREF done");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package gov.nasa.xpc.ex;
|
||||
|
||||
import gov.nasa.xpc.discovery.XPlaneConnectDiscovery;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* XPlaneConnect discovery example that prints continuously each BECN packet
|
||||
*/
|
||||
public class SimpleDiscoveryExample {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
XPlaneConnectDiscovery discovery = new XPlaneConnectDiscovery();
|
||||
discovery.onBeaconReceived(beacon -> {
|
||||
System.out.println("Discovered XPlaneConnect plugin:");
|
||||
System.out.println("Plugin version: " + beacon.getPluginVersion());
|
||||
System.out.println("X-Plane version: " + beacon.getXplaneVersion());
|
||||
System.out.println("Address: " + beacon.getXplaneAddress().getHostAddress() + ":" + beacon.getPluginPort());
|
||||
});
|
||||
discovery.start();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user