SecureClient.java Source code

Java tutorial

Introduction

Here is the source code for SecureClient.java

Source

import java.net.*;
import java.io.*;
import javax.net.*;
import java.security.*;
import javax.net.ssl.*;
import javax.crypto.*;

public class SecureClient {
    public static final int PORT = 10000;

    public static void main(String[] args) throws Exception {
        String host = "127.0.0.1";

        SocketFactory sf = SSLSocketFactory.getDefault();
        SSLSocket sock = (SSLSocket) sf.createSocket(host, PORT);
        System.out.println("Server connected");

        InputStream rawIn = sock.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(rawIn));
        System.out.println(in.readLine());
        sock.close();
    }
}