集册 Java实例教程 创建SSL客户端套接字

创建SSL客户端套接字

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

498
创建一个SSL客户端套接字
//时 代 J     a    v  a - nowjava.com 提供

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.net.Socket;


import javax.net.SocketFactory;

import javax.net.ssl.SSLSocketFactory;


public class Main {

  public void m() throws Exception {

    try {

      int port = 443;

      String hostname = "hostname";

      SocketFactory socketFactory = SSLSocketFactory.getDefault();

      Socket socket = socketFactory.createSocket(hostname, port);//来自 时代Java - nowjava.com


      // Create streams to securely send and receive data to the server

      InputStream in = socket.getInputStream();

      OutputStream out = socket.getOutputStream();


      
展开阅读全文