import java.io.DataOutputStream; import java.io.IOException; public class SendThread extends Thread{ public static final byte FORWARD = 0; public static final byte STOP = 1; public static final byte EXIT = 2; public static final byte LEFT = 3; public static final byte RIGHT = 4; public static final byte BACKWARD = 5; private int command; private int before; private boolean run; private DataOutputStream output; public SendThread(DataOutputStream out) { super(); command = -1; before = command; run = true; output = out; } @Override public void run() { while (run) { if (before != command) { try { output.write(command); } catch (IOException e) { } before = command; } try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void send (int c) { command = c; } }