import java.io.*; import java.net.*; public class ShakeThread extends Thread { protected PrintWriter sout; // Ausgabestream auf Socket public ShakeThread(Socket socket) { try { sout = new PrintWriter(socket.getOutputStream()); } catch (IOException e) { System.err.println("Error: " + e); } } public void run() { int d = 5; int pos = 0; while (true) { if (Math.abs(pos+d) > 100) d = -1*d; // andere Richtung, wenn am Rand send("rel " + d + " 0"); // Textzeile ausgeben pos += d; try { sleep(100); // 1/10 sec warten } catch (InterruptedException e) { System.err.println("Error: " + e); } } } public void send(String line) { if (line != null) { sout.println(line); // Zeile an Socket ausgeben sout.flush(); // sofort schreiben } } public void finalize() { sout.close(); // Ausgabestream schließen } }