import java.net.*; import java.io.*; public class SimpleServer { public static void main(String[] args) { ServerSocket theServerSocket; Socket theSocket; try { theServerSocket = new ServerSocket(8001); } catch (IOException e ) { System.out.println("Unable to create socket"); return; } // end try/catch System.out.println("Listening for connections on port " + theServerSocket.getLocalPort()); try { while(true) { theSocket = theServerSocket.accept(); System.out.println("Connection established with " + theSocket); ServerThread aThread = new ServerThread(theSocket.getOutputStream(),theSocket.getInputStream()); aThread.start(); } // end while } catch (IOException e) {} } // end main // this is the server action static class ServerThread extends Thread { PrintWriter out; BufferedReader in; String name; public ServerThread(OutputStream out, InputStream in) { this.out = new PrintWriter(out,true); this.in = new BufferedReader(new InputStreamReader(in)); } public void run() { try { try { while(true) { System.out.println("Waiting for Client Input"); String clientLine = in.readLine(); if( clientLine == null ) break; System.out.println("Input from client is " + clientLine); BufferedReader fin = new BufferedReader(new FileReader(clientLine)); String aLine = ""; System.out.println("Starting to read " + clientLine); while( (aLine = fin.readLine()) != null) { out.println(aLine); } // end while System.out.println("Finished Reading " + clientLine); fin.close(); } // end while } catch( IOException e ) { out.println("IOException in ServerThread run."); } // end try/catch in.close(); out.close(); } catch (IOException e) {} } // end run } // end OutputThread } // end SimpleServer