Java SSLSocket create
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; //EchoClient/* w ww . j a va 2 s .c o m*/ public class Main { public static void main(String[] args) { try { SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket("localhost", 9999); InputStreamReader inputStreamReader = new InputStreamReader(System.in); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); OutputStream outputStream = sslSocket.getOutputStream(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); BufferedWriter bufferedwriter = new BufferedWriter(outputStreamWriter); String line = null; while ((line = bufferedReader.readLine()) != null) { bufferedwriter.write(line + '\n'); bufferedwriter.flush(); } } catch (Exception exception) { exception.printStackTrace(); } } }
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; public class Main { public static void main(String[] args) { try {//from ww w.j a v a 2 s . c o m SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket ss = (SSLSocket) factory.createSocket(args[0], 6789); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedReader in = new BufferedReader(new InputStreamReader(ss.getInputStream())); PrintWriter out = new PrintWriter(ss.getOutputStream(), true); String line = null; while ((line = br.readLine()) != null) { out.println(line); System.out.println("sent --> " + line); System.out.println("received<-- " + in.readLine()); } } catch (Exception e) { e.printStackTrace(); } } }