import java.net.*;
import java.io.*;
import javax.net.ssl.*;

public class TCPSecureClient {
   public static void main (String args[]) {
      // arguments supply message and hostname and portnumber
      SSLSocket s = null;
      try{
         int serverPort = Integer.parseInt(args[2]); 
         SSLSocketFactory sslFact = (SSLSocketFactory)SSLSocketFactory.getDefault();
         s = (SSLSocket)sslFact.createSocket(args[1], serverPort);
         DataInputStream in = new DataInputStream( s.getInputStream());
         DataOutputStream out =new DataOutputStream( s.getOutputStream());
         out.writeUTF(args[0]);         // UTF is a string encoding see Sn. 4.4
         String data = in.readUTF();       // read a line of data from the stream
         System.out.println("Received: "+ data) ; 
      } catch (UnknownHostException e) {
           System.out.println("Socket:"+e.getMessage());
      } catch (EOFException e) { 
           System.out.println("EOF:"+e.getMessage());
      } catch (IOException e) {
           System.out.println("readline:"+e.getMessage());
      } finally {
           if (s!=null) 
              try {
                 s.close();
              } catch (IOException e) {
                   System.out.println("close:"+e.getMessage());
              }
      }
   }
}

