import java.io.*; import java.util.*; import java.net.*; import java.awt.*; public class ControlThreadManager { static ServerSocket mySocket; static WorkSender workSender; static PictureKeeper pictureKeeper; static long uberStartTime, uberFinishTime; static int hostPortNum; public ControlThreadManager(ServerSocket ss, WorkSender ws, PictureKeeper pk) { super(); mySocket = ss; workSender = ws; pictureKeeper = pk; uberStartTime = -1; hostPortNum = ss.getLocalPort(); } public void start() { run(); } /* public Class ConnectionHolder { public Socket connection; public void ConnectionHolder() { connection = null; } } */ public void run() { //ConnectionHolder ch = new ConnectionHolder(); Socket connection = null; /* try { connection = mySocket.accept(); Socket waste = new Socket( (InetAddress.getLocalHost()).getHostAddress(), mySocket.getLocalPort()); waste.close(); } catch (Exception e) { connection = null; } */ try { while (true) { if (pictureKeeper.weAreDone()) break; if (uberStartTime == -1) uberStartTime = System.currentTimeMillis(); // connection = mySocket.accept(); // System.out.print("Connection opened. "); // if (connection != null) // (new ControlThread(connection, workSender, // pictureKeeper)).start(); (new ControlThread(connection = mySocket.accept(), workSender, pictureKeeper)).start(); } } catch (NullPointerException e) { System.out.println("running ControlThreadManager: " + e); e.printStackTrace(); } catch (IOException e) { System.out.println("running ControlThreadManager: " + e); e.printStackTrace(); } finally { synchronized (mySocket) { try { mySocket.close(); System.out.println("Socket closed."); } catch (Exception e) { System.out.println("closing ControlThreadManager: " + e); } } } uberFinishTime = System.currentTimeMillis(); System.out.println("Total time: " + (uberFinishTime - uberStartTime)); File tempfile = new File("results"); tempfile.mkdir(); pictureKeeper.writeToFile("results/" + hostPortNum); } }