package edu.miamioh.cse283.htw;

import java.io.*;
import java.net.*;

/**
 * The server that manages the entire Cave System. Each Cave System is comprised
 * of multiple caves that are represented by {@link CaveServer}s.
 */
public class CaveSystemServer {
	// networking code
	//
	// manage new cave servers

	protected ServerSocket clientSocket;
	protected ServerSocket caveSocket;

	public static void main(String[] args) {
		try {
			CaveSystemServer s = new CaveSystemServer(Integer.parseInt(args[0]));
			s.run();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * Construct a {@link CaveSystemServer} that listens on the specified ports
	 * 
	 * @param basePort
	 *            Port number that this should start listening on for
	 *            {@link Client}s. Will listen for {@link CaveServer}s on
	 *            basePort+1
	 * 
	 * @throws IOException
	 */
	public CaveSystemServer(int basePort) throws IOException {
		clientSocket = new ServerSocket(basePort);
		caveSocket = new ServerSocket(basePort + 1);
	}

	/**
	 * The main execution logic for the {@link CaveSystemServer}; start
	 * listening for {@link Client} and {@link CaveServer} connections.
	 * 
	 * @throws IOException
	 */
	public void run() throws IOException {
		while (true) {
			Socket client = clientSocket.accept();
			(new Thread(new ServerThread(client))).start();
		}
	}

	public class ServerThread implements Runnable {
		protected Socket client;

		public ServerThread(Socket client) {
			this.client = client;
		}

		public void run() {

		}
	}
}

@@ -1600,16 +1600,332 @@
 un() %7B%0D%0A
+%09%09%09try %7B%0D%0A%09%09%09%09BufferedReader in = new BufferedReader(new InputStreamReader(%0D%0A%09%09%09%09%09%09client.getInputStream()));%0D%0A%09%09%09%09PrintWriter out = new PrintWriter(client.getOutputStream(),%0D%0A%09%09%09%09%09%09true);%0D%0A%09%09%09%09%0D%0A%09%09%09%09out.println(%22localhost%22);%0D%0A%09%09%09%09out.println(%22%22 + 1235);%0D%0A%09%09%09%7D catch (IOException e) %7B%0D%0A%09%09%09%09e.printStackTrace();%0D%0A%09%09%09%7D
 %0D%0A%09%09%7D%0D%0A%09

write code to send message to client