use of com.neuronrobotics.sdk.common.device.server.BowlerAbstractServer in project BowlerStudio by CommonWealthRobotics.
the class TestServer method main.
public static void main(String[] args) throws Exception {
class SampleBowlerServer extends BowlerAbstractServer {
BowlerAbstractDeviceServerNamespace ns = new BowlerAbstractDeviceServerNamespace(getMacAddress(), "test.thingy.*;0.3;;") {
};
public SampleBowlerServer() {
super(new MACAddress());
ns.addRpc(new RpcEncapsulation(ns.getNamespaceIndex(), ns.getNamespace(), "test", BowlerMethod.GET, new BowlerDataType[] { BowlerDataType.I32, BowlerDataType.I32, // send 3
BowlerDataType.I32 }, // integers
BowlerMethod.POST, new BowlerDataType[] { BowlerDataType.I32, BowlerDataType.I32, // get 3 integers back
BowlerDataType.I32 }, new IBowlerCommandProcessor() {
public Object[] process(Object[] data) {
for (int i = 0; i < data.length; i++) {
System.out.println("Server Got # " + data[i]);
}
return new Object[] { 37, 42, 999999 };
}
}));
addBowlerDeviceServerNamespace(ns);
Log.info("Starting UDP");
try {
startNetworkServer(1865);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// starts the UDP server
// this also starts tcp server on port+1, in this case 1866
}
}
class SampleBowlerClient extends BowlerAbstractDevice {
public void runCommand() {
Object[] args = send("test.thingy.*;0.3;;", BowlerMethod.GET, "test", // send some numbers
new Object[] { 36, 83, 13 });
for (int i = 0; i < args.length; i++) {
System.out.println("Client Received # " + args[i]);
}
}
@Override
public void onAsyncResponse(BowlerDatagram data) {
}
// no async in this demo
}
SampleBowlerClient client = new SampleBowlerClient();
// client.setConnection(new UDPBowlerConnection(InetAddress.getByName("127.0.0.1"), 1865));
// Alternately you can use the tcp connection
client.setConnection(new BowlerTCPClient("127.0.0.1", 1866));
DeviceManager.addConnection(client, "sampleClient");
// runs our test command from client to server and
client.runCommand();
// back
}
Aggregations