集册 Java实例教程 使用SSLSocketFactory和SSLSocket创建echo客户端

使用SSLSocketFactory和SSLSocket创建echo客户端

欢马劈雪     最近更新时间:2020-01-02 10:19:05

527
使用SSLSocketFactory和SSLSocket创建回显客户端

import java.io.BufferedReader;//from 时 代 J a v a - nowjava.com

import java.io.BufferedWriter;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import javax.net.ssl.SSLSocket;

import javax.net.ssl.SSLSocketFactory;


public class Main {

    public static void main(String[] args) {

        try {

            SSLSocketFactory sslSocketFactory = /** from 时 代 J a v a - N o w J a v a . c o m**/

                    (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;

            
展开阅读全文