集册 Java实例教程 创建SSL服务器套接字

创建SSL服务器套接字

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

499
创建一个SSL服务器套接字

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.net.ServerSocket;
/**
来 自 时   代     Java  公  众  号 - nowjava.com
**/

import java.net.Socket;


import javax.net.ServerSocketFactory;

import javax.net.ssl.SSLServerSocketFactory;


public class Main {

  public static void main(String[] argv) {

    try {

      int port = 443;

      ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();

      ServerSocket ssocket = ssocketFactory.createServerSocket(port);


      // Listen for connections

      Socket socket = ssocket.accept();/**来 自 NowJava.com**/


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

      InputStream in = socket.getInputStream();

      OutputStream out = socket.getOutputStream();


 
展开阅读全文