Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#CCCCFF
// Exception handling has been omitted for the sake of brevity
class EchoServer {
  public static void main(String[] args) throws IOException {   
    SSLServerSocketFactory sslserversocketfactory =
      (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    SSLServerSocket sslserversocket =
      (SSLServerSocket) sslserversocketfactory.createServerSocket(9999);
    SSLSocket sslsocket = (SSLSocket) sslserversocket.accept();

    PrintWriter out = new PrintWriter( sslsocket.getOutputStream(),true);
    BufferedReader in = new BufferedReader(
      new InputStreamReader( sslsocket.getInputStream()));
            
    String inputLine; 
            
    while ((inputLine = in.readLine()) != null) { 
      System.out.println(inputLine); 
      out.println(inputLine); 
    } 

    // close out, in, sslsocket (preferably in a try-finally block)
  }
}

class EchoClient {
  public static void main(String[] args) throws IOException {
    SSLSocketFactory sslsocketfactory =
      (SSLSocketFactory) SSLSocketFactory.getDefault();
    SSLSocket sslsocket =
      (SSLSocket) sslsocketfactory.createSocket("localhost", 9999);

    PrintWriter out = new PrintWriter(sslsocket.getOutputStream(), true);
    BufferedReader in = new BufferedReader(
      new InputStreamReader(sslsocket.getInputStream()));
			
    BufferedReader stdIn = new BufferedReader(
      new InputStreamReader(System.in));
            
    String userInput;

    while ((userInput = stdIn.readLine()) != null) {
      out.println(userInput);
      System.out.println(in.readLine());
    }
  
    // close out, in, stdIn, sslsocket (preferably in a try-finally block)
  }
}

...