Java client BECN implementation (#155)

This commit is contained in:
Jan Chaloupecky
2019-06-01 20:52:13 +01:00
committed by Jason Watkins
parent 90ccec0d07
commit c018d6c3be
14 changed files with 379 additions and 4 deletions

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="gov.nasa.xpc.ex" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="XPlaneConnect" />
</component>
</module>

View File

@@ -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");
}
}

View File

@@ -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();
}
}