Replace tabs with spaces

This commit is contained in:
2015-09-01 13:19:01 +01:00
parent 6590ddac10
commit 4283a2ebc4
10 changed files with 408 additions and 408 deletions

View File

@@ -11,51 +11,51 @@ import com.github.boukefalos.ibuddy.implementation.Remote;
public class Loader extends AbstractLoader<Loader> { public class Loader extends AbstractLoader<Loader> {
protected static final String PROPERTIES_FILE = "ibuddy.properties"; protected static final String PROPERTIES_FILE = "ibuddy.properties";
public Loader(Properties properties) throws LoaderException { public Loader(Properties properties) throws LoaderException {
super(); super();
/* Add implementation */ /* Add implementation */
switch (properties.getProperty("implementation")) { switch (properties.getProperty("implementation")) {
case "local": case "local":
pico.addComponent(Local.class); pico.addComponent(Local.class);
break; break;
case "remote": case "remote":
pico.addComponent(Remote.class); pico.addComponent(Remote.class);
/* Add sender implementation */ /* Add sender implementation */
try { try {
String protocol = properties.getOrDefault("protocol", "tcp").toString(); String protocol = properties.getOrDefault("protocol", "tcp").toString();
String implementation = properties.getOrDefault("tcp.implementation", "socket").toString(); String implementation = properties.getOrDefault("tcp.implementation", "socket").toString();
String host = properties.getProperty("remote.host"); String host = properties.getProperty("remote.host");
int port = Integer.valueOf(properties.getProperty("remote.port")); int port = Integer.valueOf(properties.getProperty("remote.port"));
addClientSender(protocol, implementation, host, port); addClientSender(protocol, implementation, host, port);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new LoaderException("Failed to parse remote.port"); throw new LoaderException("Failed to parse remote.port");
} }
break; break;
} }
/* Add server */ /* Add server */
if (properties.getProperty("server") != null) { if (properties.getProperty("server") != null) {
pico.addComponent(Server.class); pico.addComponent(Server.class);
/* Add server forwarder implementation */ /* Add server forwarder implementation */
try { try {
String protocol = properties.getOrDefault("server.protocol", "tcp").toString(); String protocol = properties.getOrDefault("server.protocol", "tcp").toString();
String implementation = properties.getOrDefault("tcp.implementation", "socket").toString(); String implementation = properties.getOrDefault("tcp.implementation", "socket").toString();
int port = Integer.valueOf(properties.getProperty("server.port")); int port = Integer.valueOf(properties.getProperty("server.port"));
addServerForwarder(protocol, implementation, port); addServerForwarder(protocol, implementation, port);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new LoaderException("Failed to parse server.port"); throw new LoaderException("Failed to parse server.port");
} }
} }
} }
public iBuddy getiBuddy() { public iBuddy getiBuddy() {
return pico.getComponent(iBuddy.class); return pico.getComponent(iBuddy.class);
} }
public Server getServer() { public Server getServer() {
return pico.getComponent(Server.class); return pico.getComponent(Server.class);
} }
} }

View File

@@ -16,68 +16,68 @@ import base.Forwarder;
import base.server.receiver.AbstractReceiver; import base.server.receiver.AbstractReceiver;
public class Server extends AbstractReceiver { public class Server extends AbstractReceiver {
protected iBuddy iBuddy; protected iBuddy iBuddy;
public Server(iBuddy iBuddy, Forwarder forwarder) { public Server(iBuddy iBuddy, Forwarder forwarder) {
super(forwarder); super(forwarder);
this.iBuddy = iBuddy; this.iBuddy = iBuddy;
} }
public void receive(byte[] buffer) { public void receive(byte[] buffer) {
ByteArrayInputStream input = new ByteArrayInputStream(buffer); ByteArrayInputStream input = new ByteArrayInputStream(buffer);
logger.debug("Received input"); logger.debug("Received input");
try { try {
Command command = Command.parseDelimitedFrom(input); Command command = Command.parseDelimitedFrom(input);
logger.debug("Command type = " + command.getType().name()); logger.debug("Command type = " + command.getType().name());
switch (command.getType()) { switch (command.getType()) {
case HEAD: case HEAD:
Head head = command.getHead(); Head head = command.getHead();
Color color = head.getColor(); Color color = head.getColor();
if (head.getSingle()) { if (head.getSingle()) {
boolean state = head.getState().equals(State.ON); boolean state = head.getState().equals(State.ON);
switch (color) { switch (color) {
case RED: case RED:
iBuddy.setHeadRed(state); iBuddy.setHeadRed(state);
case GREEN: case GREEN:
iBuddy.setHeadGreen(state); iBuddy.setHeadGreen(state);
case BLUE: case BLUE:
iBuddy.setHeadBlue(state); iBuddy.setHeadBlue(state);
default: default:
break; break;
} }
} else { } else {
iBuddy.setHead(color); iBuddy.setHead(color);
} }
break; break;
case WINGS: case WINGS:
iBuddy.setWings(command.getWings().getDirection()); iBuddy.setWings(command.getWings().getDirection());
break; break;
case ROTATE: case ROTATE:
iBuddy.setRotate(command.getRotate().getDirection()); iBuddy.setRotate(command.getRotate().getDirection());
break; break;
case HEART: case HEART:
iBuddy.setHeart(command.getHeart().getState().equals(State.ON)); iBuddy.setHeart(command.getHeart().getState().equals(State.ON));
break; break;
case BLINK: case BLINK:
Blink blink = command.getBlink(); Blink blink = command.getBlink();
iBuddy.blink(blink.getColor(), blink.getOnTime(), blink.getOffTime(), blink.getTimes()); iBuddy.blink(blink.getColor(), blink.getOnTime(), blink.getOffTime(), blink.getTimes());
break; break;
case NUDGE: case NUDGE:
Nudge nudge = command.getNudge(); Nudge nudge = command.getNudge();
iBuddy.nudge(nudge.getDelay(), nudge.getTimes()); iBuddy.nudge(nudge.getDelay(), nudge.getTimes());
break; break;
case FLAP: case FLAP:
Flap flap = command.getFlap(); Flap flap = command.getFlap();
iBuddy.flap(flap.getDelay(), flap.getTimes()); iBuddy.flap(flap.getDelay(), flap.getTimes());
break; break;
default: default:
iBuddy.off(); iBuddy.off();
} }
} catch (IOException e) { } catch (IOException e) {
logger.error("Failed to parse input"); logger.error("Failed to parse input");
return; return;
} catch (IBuddyException e) { } catch (IBuddyException e) {
logger.error("Failed to send command to iBuddy", e); logger.error("Failed to send command to iBuddy", e);
} }
} }
} }

View File

@@ -1,6 +1,6 @@
package com.github.boukefalos.ibuddy.exception; package com.github.boukefalos.ibuddy.exception;
public class iBuddyException extends Exception { public class iBuddyException extends Exception {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }

View File

@@ -7,21 +7,21 @@ import proto.Ibuddy.Direction;
import base.Control; import base.Control;
public interface iBuddy extends Control { public interface iBuddy extends Control {
public void setHeart(boolean on) throws IBuddyException; public void setHeart(boolean on) throws IBuddyException;
public void setHeadRed(boolean on) throws IBuddyException; public void setHeadRed(boolean on) throws IBuddyException;
public void setHeadBlue(boolean on) throws IBuddyException; public void setHeadBlue(boolean on) throws IBuddyException;
public void setHeadGreen(boolean on) throws IBuddyException; public void setHeadGreen(boolean on) throws IBuddyException;
public void setHead(Color color) throws IBuddyException; public void setHead(Color color) throws IBuddyException;
public void setWingsUp() throws IBuddyException; public void setWingsUp() throws IBuddyException;
public void setWingsDown() throws IBuddyException; public void setWingsDown() throws IBuddyException;
public void setWingsCenter() throws IBuddyException; public void setWingsCenter() throws IBuddyException;
public void setWings(Direction direction) throws IBuddyException; public void setWings(Direction direction) throws IBuddyException;
public void setRotateLeft() throws IBuddyException; public void setRotateLeft() throws IBuddyException;
public void setRotateRight() throws IBuddyException; public void setRotateRight() throws IBuddyException;
public void setRotateCenter() throws IBuddyException; public void setRotateCenter() throws IBuddyException;
public void setRotate(Direction direction) throws IBuddyException; public void setRotate(Direction direction) throws IBuddyException;
public void off() throws IBuddyException; public void off() throws IBuddyException;
public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException; public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException;
public void nudge(int delay, int times) throws IBuddyException; public void nudge(int delay, int times) throws IBuddyException;
public void flap(int delay, int times) throws IBuddyException; public void flap(int delay, int times) throws IBuddyException;
} }

View File

@@ -10,107 +10,107 @@ import proto.Ibuddy.Direction;
import com.github.boukefalos.ibuddy.iBuddy; import com.github.boukefalos.ibuddy.iBuddy;
public class Local implements iBuddy { public class Local implements iBuddy {
IBuddy IBuddy; IBuddy IBuddy;
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public Local() { public Local() {
IBuddy = IBuddy.getIBuddy(); IBuddy = IBuddy.getIBuddy();
} }
public void start() {} public void start() {}
public void stop() {} public void stop() {}
public void exit() {} public void exit() {}
public void setHeadRed(boolean on) throws IBuddyException { public void setHeadRed(boolean on) throws IBuddyException {
IBuddy.sendHeadRed(on); IBuddy.sendHeadRed(on);
} }
public void setHeadBlue(boolean on) throws IBuddyException { public void setHeadBlue(boolean on) throws IBuddyException {
IBuddy.sendHeadBlue(on); IBuddy.sendHeadBlue(on);
} }
public void setHeadGreen(boolean on) throws IBuddyException { public void setHeadGreen(boolean on) throws IBuddyException {
IBuddy.sendHeadGreen(on); IBuddy.sendHeadGreen(on);
} }
public void setHeart(boolean on) throws IBuddyException { public void setHeart(boolean on) throws IBuddyException {
IBuddy.sendHeart(on); IBuddy.sendHeart(on);
} }
public void setHead(Color color) throws IBuddyException { public void setHead(Color color) throws IBuddyException {
IBuddy.sendHeadColor(mapColor(color)); IBuddy.sendHeadColor(mapColor(color));
} }
public void setWingsUp() throws IBuddyException { public void setWingsUp() throws IBuddyException {
IBuddy.sendWings(false, true); IBuddy.sendWings(false, true);
} }
public void setWingsDown() throws IBuddyException { public void setWingsDown() throws IBuddyException {
IBuddy.sendWings(true, false); IBuddy.sendWings(true, false);
} }
public void setWingsCenter() throws IBuddyException { public void setWingsCenter() throws IBuddyException {
IBuddy.sendWings(false, false); IBuddy.sendWings(false, false);
} }
public void setWings(Direction direction) throws IBuddyException { public void setWings(Direction direction) throws IBuddyException {
switch (direction) { switch (direction) {
case UP: case UP:
setWingsUp(); setWingsUp();
break; break;
case DOWN: case DOWN:
setWingsDown(); setWingsDown();
break; break;
default: default:
setWingsCenter(); setWingsCenter();
break; break;
} }
} }
public void setRotateLeft() throws IBuddyException { public void setRotateLeft() throws IBuddyException {
IBuddy.sendRotate(false, true); IBuddy.sendRotate(false, true);
} }
public void setRotateRight() throws IBuddyException { public void setRotateRight() throws IBuddyException {
IBuddy.sendRotate(true, false); IBuddy.sendRotate(true, false);
} }
public void setRotateCenter() throws IBuddyException { public void setRotateCenter() throws IBuddyException {
IBuddy.sendRotate(false, false); IBuddy.sendRotate(false, false);
} }
public void setRotate(Direction direction) throws IBuddyException { public void setRotate(Direction direction) throws IBuddyException {
switch (direction) { switch (direction) {
case LEFT: case LEFT:
setRotateLeft(); setRotateLeft();
break; break;
case RIGHT: case RIGHT:
setRotateRight(); setRotateRight();
default: default:
setRotateCenter(); setRotateCenter();
} }
} }
public void off() throws IBuddyException { public void off() throws IBuddyException {
IBuddy.sendAllOff(); IBuddy.sendAllOff();
} }
public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException { public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException {
IBuddyUtils.blink(IBuddy, mapColor(color), onTime, offTime, times); IBuddyUtils.blink(IBuddy, mapColor(color), onTime, offTime, times);
} }
public void nudge(int delay, int times) throws IBuddyException { public void nudge(int delay, int times) throws IBuddyException {
IBuddyUtils.nudge(IBuddy, delay, times); IBuddyUtils.nudge(IBuddy, delay, times);
} }
public void flap(int delay, int times) throws IBuddyException { public void flap(int delay, int times) throws IBuddyException {
IBuddyUtils.flap(IBuddy, delay, times); IBuddyUtils.flap(IBuddy, delay, times);
} }
protected org.jraf.jlibibuddy.IBuddy.Color mapColor(Color color) { protected org.jraf.jlibibuddy.IBuddy.Color mapColor(Color color) {
return color.equals(Color.NONE) return color.equals(Color.NONE)
? org.jraf.jlibibuddy.IBuddy.Color.OFF ? org.jraf.jlibibuddy.IBuddy.Color.OFF
: org.jraf.jlibibuddy.IBuddy.Color.valueOf(color.name()); : org.jraf.jlibibuddy.IBuddy.Color.valueOf(color.name());
} }
} }

View File

@@ -25,162 +25,162 @@ import base.Sender;
import com.github.boukefalos.ibuddy.iBuddy; import com.github.boukefalos.ibuddy.iBuddy;
public class Remote implements iBuddy, Control { public class Remote implements iBuddy, Control {
protected final static int BUFFER_SIZE = 1024; protected final static int BUFFER_SIZE = 1024;
protected Logger logger = LoggerFactory.getLogger(getClass()); protected Logger logger = LoggerFactory.getLogger(getClass());
protected Sender sender; protected Sender sender;
public Remote(Sender sender) { public Remote(Sender sender) {
this.sender = sender; this.sender = sender;
} }
public void start() { public void start() {
sender.start(); sender.start();
} }
public void stop() { public void stop() {
sender.stop(); sender.stop();
} }
public void exit() { public void exit() {
sender.exit(); sender.exit();
} }
public void setHeart(boolean on) throws IBuddyException { public void setHeart(boolean on) throws IBuddyException {
send( send(
Command.newBuilder() Command.newBuilder()
.setType(Type.HEART) .setType(Type.HEART)
.setHeart(Heart.newBuilder() .setHeart(Heart.newBuilder()
.setState(mapState(on))).build()); .setState(mapState(on))).build());
} }
public void setHeadRed(boolean on) throws IBuddyException { public void setHeadRed(boolean on) throws IBuddyException {
send( send(
Command.newBuilder() Command.newBuilder()
.setType(Type.HEAD) .setType(Type.HEAD)
.setHead(Head.newBuilder() .setHead(Head.newBuilder()
.setState(mapState(on)) .setState(mapState(on))
.setSingle(true) .setSingle(true)
.setColor(Color.RED)).build()); .setColor(Color.RED)).build());
} }
public void setHeadBlue(boolean on) throws IBuddyException { public void setHeadBlue(boolean on) throws IBuddyException {
send( send(
Command.newBuilder() Command.newBuilder()
.setType(Type.HEAD) .setType(Type.HEAD)
.setHead(Head.newBuilder() .setHead(Head.newBuilder()
.setState(mapState(on)) .setState(mapState(on))
.setSingle(true) .setSingle(true)
.setColor(Color.BLUE)).build()); .setColor(Color.BLUE)).build());
} }
public void setHeadGreen(boolean on) throws IBuddyException { public void setHeadGreen(boolean on) throws IBuddyException {
send( send(
Command.newBuilder() Command.newBuilder()
.setType(Type.HEAD) .setType(Type.HEAD)
.setHead(Head.newBuilder() .setHead(Head.newBuilder()
.setState(mapState(on)) .setState(mapState(on))
.setSingle(true) .setSingle(true)
.setColor(Color.GREEN)).build()); .setColor(Color.GREEN)).build());
} }
public void setHead(Color color) throws IBuddyException { public void setHead(Color color) throws IBuddyException {
State state = mapState(!color.equals(Color.NONE)); State state = mapState(!color.equals(Color.NONE));
send( send(
Command.newBuilder() Command.newBuilder()
.setType(Type.HEAD) .setType(Type.HEAD)
.setHead(Head.newBuilder() .setHead(Head.newBuilder()
.setState(state) .setState(state)
.setSingle(false) .setSingle(false)
.setColor(color)).build()); .setColor(color)).build());
} }
public void setWingsUp() throws IBuddyException { public void setWingsUp() throws IBuddyException {
setWings(Direction.UP); setWings(Direction.UP);
} }
public void setWingsDown() throws IBuddyException { public void setWingsDown() throws IBuddyException {
setWings(Direction.DOWN); setWings(Direction.DOWN);
} }
public void setWingsCenter() throws IBuddyException { public void setWingsCenter() throws IBuddyException {
setWings(Direction.CENTER); setWings(Direction.CENTER);
} }
public void setWings(Direction direction) throws IBuddyException { public void setWings(Direction direction) throws IBuddyException {
send( send(
Command.newBuilder() Command.newBuilder()
.setType(Type.WINGS) .setType(Type.WINGS)
.setWings(Wings.newBuilder() .setWings(Wings.newBuilder()
.setDirection(direction)).build()); .setDirection(direction)).build());
} }
public void setRotateLeft() throws IBuddyException { public void setRotateLeft() throws IBuddyException {
setRotate(Direction.LEFT); setRotate(Direction.LEFT);
} }
public void setRotateRight() throws IBuddyException { public void setRotateRight() throws IBuddyException {
setRotate(Direction.RIGHT); setRotate(Direction.RIGHT);
} }
public void setRotateCenter() throws IBuddyException { public void setRotateCenter() throws IBuddyException {
setRotate(Direction.CENTER); setRotate(Direction.CENTER);
} }
public void setRotate(Direction direction) throws IBuddyException { public void setRotate(Direction direction) throws IBuddyException {
send( send(
Command.newBuilder() Command.newBuilder()
.setType(Type.ROTATE) .setType(Type.ROTATE)
.setRotate(Rotate.newBuilder() .setRotate(Rotate.newBuilder()
.setDirection(direction)).build()); .setDirection(direction)).build());
} }
public void off() throws IBuddyException { public void off() throws IBuddyException {
send( send(
Command.newBuilder() Command.newBuilder()
.setType(Type.STATE).build()); .setType(Type.STATE).build());
} }
public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException { public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException {
send( send(
Command.newBuilder() Command.newBuilder()
.setType(Type.BLINK) .setType(Type.BLINK)
.setBlink(Blink.newBuilder() .setBlink(Blink.newBuilder()
.setOnTime(onTime) .setOnTime(onTime)
.setOffTime(offTime) .setOffTime(offTime)
.setTimes(times)).build()); .setTimes(times)).build());
} }
public void nudge(int delay, int times) throws IBuddyException { public void nudge(int delay, int times) throws IBuddyException {
send( send(
Command.newBuilder() Command.newBuilder()
.setType(Type.NUDGE) .setType(Type.NUDGE)
.setNudge(Nudge.newBuilder() .setNudge(Nudge.newBuilder()
.setDelay(delay) .setDelay(delay)
.setTimes(times)).build()); .setTimes(times)).build());
} }
public void flap(int delay, int times) throws IBuddyException { public void flap(int delay, int times) throws IBuddyException {
send( send(
Command.newBuilder() Command.newBuilder()
.setType(Type.FLAP) .setType(Type.FLAP)
.setFlap(Flap.newBuilder() .setFlap(Flap.newBuilder()
.setDelay(delay) .setDelay(delay)
.setTimes(times)).build()); .setTimes(times)).build());
} }
protected static State mapState(boolean on) { protected static State mapState(boolean on) {
return on ? State.ON : State.OFF; return on ? State.ON : State.OFF;
} }
protected void send(Command command) { protected void send(Command command) {
ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE); ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE);
try { try {
command.writeDelimitedTo(output); command.writeDelimitedTo(output);
sender.send(output.toByteArray()); sender.send(output.toByteArray());
} catch (IOException e) { } catch (IOException e) {
logger.error("Failed to send command"); logger.error("Failed to send command");
} }
} }
} }

View File

@@ -205,18 +205,18 @@ public class IBuddy {
* @param command the command byte. * @param command the command byte.
*/ */
private synchronized void sendMessage(byte command) throws IBuddyException { private synchronized void sendMessage(byte command) throws IBuddyException {
open(); open();
try { try {
device.controlMsg(USB.REQ_TYPE_TYPE_CLASS | USB.REQ_TYPE_RECIP_INTERFACE, USB.REQ_SET_CONFIGURATION, 0x02, 0x01, INIT, INIT.length, 100, true); device.controlMsg(USB.REQ_TYPE_TYPE_CLASS | USB.REQ_TYPE_RECIP_INTERFACE, USB.REQ_SET_CONFIGURATION, 0x02, 0x01, INIT, INIT.length, 100, true);
} catch (USBException e) { } catch (USBException e) {
close(); close();
throw new IBuddyException("Could not send message to i-Buddy", e); throw new IBuddyException("Could not send message to i-Buddy", e);
} }
byte[] commandMessage = getCommandMessage(command); byte[] commandMessage = getCommandMessage(command);
try { try {
device.controlMsg(USB.REQ_TYPE_TYPE_CLASS | USB.REQ_TYPE_RECIP_INTERFACE, USB.REQ_SET_CONFIGURATION, 0x02, 0x01, commandMessage, commandMessage.length, 100, true); device.controlMsg(USB.REQ_TYPE_TYPE_CLASS | USB.REQ_TYPE_RECIP_INTERFACE, USB.REQ_SET_CONFIGURATION, 0x02, 0x01, commandMessage, commandMessage.length, 100, true);
} catch (USBException e) { } catch (USBException e) {
close(); close();
throw new IBuddyException("Could not send message to i-Buddy", e); throw new IBuddyException("Could not send message to i-Buddy", e);
} }
close(); close();

View File

@@ -5,26 +5,26 @@ import org.jraf.jlibibuddy.IBuddyException;
import org.jraf.jlibibuddy.IBuddyUtils; import org.jraf.jlibibuddy.IBuddyUtils;
public class TestOriginal { public class TestOriginal {
public static void main(String[] args) { public static void main(String[] args) {
IBuddy iBuddy = IBuddy.getIBuddy(); IBuddy iBuddy = IBuddy.getIBuddy();
try { try {
while (true) { while (true) {
iBuddy.sendAllOff(); iBuddy.sendAllOff();
for (Color color : IBuddy.Color.values()) { for (Color color : IBuddy.Color.values()) {
iBuddy.sendHeart(false); iBuddy.sendHeart(false);
iBuddy.sendHeadColor(color); iBuddy.sendHeadColor(color);
Thread.sleep(100); Thread.sleep(100);
iBuddy.sendHeart(true); iBuddy.sendHeart(true);
Thread.sleep(500); Thread.sleep(500);
} }
iBuddy.sendAllOff(); iBuddy.sendAllOff();
Thread.sleep(2000); Thread.sleep(2000);
IBuddyUtils.flap(iBuddy, 400, 6); IBuddyUtils.flap(iBuddy, 400, 6);
} }
} catch (IBuddyException e) { } catch (IBuddyException e) {
e.printStackTrace(); e.printStackTrace();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

View File

@@ -9,36 +9,36 @@ import com.github.boukefalos.ibuddy.Server;
import com.github.boukefalos.ibuddy.iBuddy; import com.github.boukefalos.ibuddy.iBuddy;
public class TestTcpCommunication { public class TestTcpCommunication {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
Properties localProperties = new Properties(); Properties localProperties = new Properties();
localProperties.setProperty("implementation", "local"); localProperties.setProperty("implementation", "local");
localProperties.setProperty("server", "true"); localProperties.setProperty("server", "true");
localProperties.setProperty("server.port", "8883"); localProperties.setProperty("server.port", "8883");
localProperties.setProperty("server.protocol", "tcp"); localProperties.setProperty("server.protocol", "tcp");
localProperties.setProperty("tcp.implementation", "socket"); localProperties.setProperty("tcp.implementation", "socket");
Properties remoteProperties = new Properties(); Properties remoteProperties = new Properties();
remoteProperties.setProperty("implementation", "remote"); remoteProperties.setProperty("implementation", "remote");
remoteProperties.setProperty("protocol", "tcp"); remoteProperties.setProperty("protocol", "tcp");
remoteProperties.setProperty("remote.host", "localhost"); remoteProperties.setProperty("remote.host", "localhost");
remoteProperties.setProperty("remote.port", "8883"); remoteProperties.setProperty("remote.port", "8883");
Loader localLoader = new Loader(localProperties); Loader localLoader = new Loader(localProperties);
Loader remoteLoader = new Loader(remoteProperties); Loader remoteLoader = new Loader(remoteProperties);
Server server = localLoader.getServer(); Server server = localLoader.getServer();
iBuddy iBuddy = remoteLoader.getiBuddy(); iBuddy iBuddy = remoteLoader.getiBuddy();
server.start(); server.start();
iBuddy.start(); iBuddy.start();
iBuddy.setHead(Color.GREEN); iBuddy.setHead(Color.GREEN);
server.exit(); server.exit();
iBuddy.exit(); iBuddy.exit();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

View File

@@ -9,36 +9,36 @@ import com.github.boukefalos.ibuddy.Server;
import com.github.boukefalos.ibuddy.iBuddy; import com.github.boukefalos.ibuddy.iBuddy;
public class TestUdpCommunication { public class TestUdpCommunication {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
Properties localProperties = new Properties(); Properties localProperties = new Properties();
localProperties.setProperty("implementation", "local"); localProperties.setProperty("implementation", "local");
localProperties.setProperty("protocol", "udp"); localProperties.setProperty("protocol", "udp");
localProperties.setProperty("server", "true"); localProperties.setProperty("server", "true");
localProperties.setProperty("server.port", "8883"); localProperties.setProperty("server.port", "8883");
localProperties.setProperty("server.protocol", "udp"); localProperties.setProperty("server.protocol", "udp");
Properties remoteProperties = new Properties(); Properties remoteProperties = new Properties();
remoteProperties.setProperty("implementation", "remote"); remoteProperties.setProperty("implementation", "remote");
remoteProperties.setProperty("protocol", "udp"); remoteProperties.setProperty("protocol", "udp");
remoteProperties.setProperty("remote.host", "255.255.255.255"); remoteProperties.setProperty("remote.host", "255.255.255.255");
remoteProperties.setProperty("remote.port", "8883"); remoteProperties.setProperty("remote.port", "8883");
Loader localLoader = new Loader(localProperties); Loader localLoader = new Loader(localProperties);
Loader remoteLoader = new Loader(remoteProperties); Loader remoteLoader = new Loader(remoteProperties);
iBuddy iBuddy = remoteLoader.getiBuddy(); iBuddy iBuddy = remoteLoader.getiBuddy();
Server server = localLoader.getServer(); Server server = localLoader.getServer();
iBuddy.start(); iBuddy.start();
server.start(); server.start();
iBuddy.setHead(Color.WHITE); iBuddy.setHead(Color.WHITE);
server.exit(); server.exit();
iBuddy.exit(); iBuddy.exit();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }