import java.io.*; import java.util.*; import java.net.*; import java.awt.*; public class ControlThread extends Thread { static Socket connection; static WorkSender workSender; static PictureKeeper pictureKeeper; public ControlThread(Socket con, WorkSender ws, PictureKeeper pk) { super(); connection = con; workSender = ws; pictureKeeper = pk; } public void run() { synchronized (connection) { try { System.out.println("Anonymous thread successfully started!"); InputStream is = connection.getInputStream(); ObjectInputStream ois = new ObjectInputStream(is); char connectType = '0'; connectType = ((Character) ois.readObject()).charValue(); System.out.println("Got char: " + connectType); if (connectType == 'y' || connectType == 'n') { //ois.close(); //is.close(); ObjectOutputStream oos = new ObjectOutputStream( connection.getOutputStream()); if (connectType == 'y') workSender.sendWorld(oos); workSender.sendLine(oos); oos.close(); } else if (connectType == 'r') { int resultLine = ((Integer) ois.readObject()).intValue(); Scanline line = (Scanline) ois.readObject(); pictureKeeper.storeLine(resultLine, line); ois.close(); } connection.close(); System.out.println("Connection closed. "); System.out.println("----------------------"); } catch (Exception e) { System.out.println("running ControlThread: " + e); e.printStackTrace(); System.out.println("======================"); } } } }