import java.net.*; import java.io.*; import java.lang.*; import java.util.*; public class ServerThread extends Thread { private Socket socket = null; public ServerThread(Socket socket) { super("ServerThread"); this.socket = socket; } public void run() { try { ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); // putStream(), true);?? ObjectInputStream in = new ObjectInputStream(socket.getInputStream()); String inputLine; Vector outputVector; Object inputObject; cd cd_var; collection c = new collection(); outputVector = c.processInput(null); // starts with no input see collection2 (protocol) if (outputVector != null) send_objects(outputVector, out); while ((inputObject = in.readObject())!= null) { inputLine = (String)inputObject; if (inputLine.equals("sending_cd")) { // for receiving cd objects if ((inputObject = in.readObject())!= null) { // grabs next object - cd c.addCD((cd)inputObject); } } else { // ie.string != sending_cd outputVector = c.processInput(inputLine); if (outputVector != null) send_objects(outputVector, out); } } out.close(); in.close(); socket.close(); } catch (EOFException e) { System.out.println("Client thread terminated."); Server.threads--; // remove thread number from Server count. } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("Class exception!"); } } private void send_objects(Vector output, ObjectOutputStream o) throws IOException { try { if ((output.size()) > 0) { o.writeObject("SENDING"); // start of transmission*** o.flush(); for (int i = 0; i < output.size(); i++) { cd element = (cd)output.elementAt(i); o.writeObject(element); // send each cd object. o.flush(); } o.writeObject(null); } else o.writeObject("NOT SENDING"); // says finished!! send back error response o.flush(); o.reset(); } catch (NullPointerException e) { System.err.println(e); System.out.println("Null Pointer Exception!***"); } } }