源码

java – 如何做ssl socket编程


我正在通过以下IP地址进行套接字通信但是我不想在ssl模式下进行通信,但是如何更改InetAddress serverAddr = InetAddress.getByName(“192.168.1.2”);到SSL.

public class TCPClient implements Runnable {

    public void run() {

     try {

         InetAddress serverAddr = InetAddress.getByName("192.168.1.2");

             Log.d("TCP", "C: Connecting...");

             Socket socket = new Socket(serverAddr,12345);

             String message = "Hello from Client android emulator";
              try {

                     Log.d("TCP", "C: Sending: '" + message + "'");

                     PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true);

                     out.println(message);

                     Log.d("TCP", "C: Sent.");

                 Log.d("TCP", "C: Done.");



         } catch(Exception e) {

             Log.e("TCP", "S: Error", e);
                 } finally {

                    socket.close();

                  }
     } catch (Exception e) {

          Log.e("TCP", "C: Error", e);

     }

}

}
(0)

本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/java-ruhezuossl-socketbiancheng.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:9月 27, 2019 at 04:24 上午

热评文章