thomasguenzel
thomasguenzel

Reputation: 670

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

Upvotes: 3

Views: 8269

Answers (1)

Francis Upton IV
Francis Upton IV

Reputation: 19443

I found this with a quick Google search.

Here.

Upvotes: 2

Related Questions