简体   繁体   中英

How to make a SSL tcp server with java?

i'm trying to find out how to create a TCP server with SSL in java. But i don't get what i really need. Do i have to import key-files into java, and i so, how to do this? Or do i just need to change the type of the socket from Socket to SSLSocket? I've read some articles but couldn't find anything helpful because all of them just take http for communicating. I would need it for my own protocol. In my case it would be to have a program like this:

    int port = 4444;
    ServerSocket serverSocket = new ServerSocket(port);
    System.err.println("Started server on port " + port);

    // repeatedly wait for connections, and process
    while (true) {

        // a "blocking" call which waits until a connection is requested
        Socket clientSocket = serverSocket.accept();
        System.err.println("Accepted connection from client");

        // open up IO streams
        In  in  = new In (clientSocket);
        Out out = new Out(clientSocket);

        // waits for data and reads it in until connection dies
        // readLine() blocks until the server receives a new line from client
        String s;
        while ((s = in.readLine()) != null) {
            out.println(s);
        }

        // close IO streams, then socket
        System.err.println("Closing connection with client");
        out.close();
        in.close();
        clientSocket.close();
    }

to use a SSL connection. So how to do this?

Thanks, Thomas

I found this with a quick Google search.

Here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM