import java.io.*; import java.net.*; import java.util.*; public class Server{ public static void main(String[] args){ Server simpleserver = new Server(); simpleserver.init(); } public void init(){ ServerSocket serversocket = null; Socket socket = null; try{ serversocket = new ServerSocket(8189); System.out.println("Listening at 127.0.0.1 on port 8189"); socket = serversocket.accept(); PrintWriter printwriter = new PrintWriter(socket.getOutputStream(),true); InputStreamReader inputstreamreader = new InputStreamReader(socket.getInputStream()); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); String datetimestring = (Calendar.getInstance()).getTime().toString(); printwriter.println("You connected at " + datetimestring); String lineread = ""; lineread = bufferedreader.readLine(); char selection; Scanner input = new Scanner(System.in); selection = lineread.charAt(0); switch(selection) { case 's': case 'S': try { [COLOR="red"] FileInputStream fstream = new FileInputStream("shows.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br1 = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br1.readLine()) != null) { System.out.println(""); System.out.println (strLine); }[/COLOR] in.close(); } catch (Exception e){System.err.println("Error: " + e.getMessage());} } System.out.println("Closing connection."); bufferedreader.close(); inputstreamreader.close(); printwriter.close(); socket.close(); }catch(UnknownHostException unhe){ System.out.println("UnknownHostException: " + unhe.getMessage()); }catch(InterruptedIOException intioe){ System.out.println("Timeout while attempting to establish socket connection."); }catch(IOException ioe){ System.out.println("IOException: " + ioe.getMessage()); }finally{ try{ socket.close(); serversocket.close(); }catch(IOException ioe){ System.out.println("IOException: " + ioe.getMessage()); } } } }