// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;
import java.net.*;

import javax.net.ssl.*;

public class MultiServer {
    private final static int PORT = 12345; 
    public static void main(String[] args) throws Exception {
        ServerSocket ss;
        if(args.length > 0 && args[0].equals("SSL")) {
            System.out.println("SSL");
            ss = SSLServerSocketFactory.getDefault().createServerSocket(PORT);
        } else {
            System.out.println("Non-SSL");
            ss = new ServerSocket(PORT);
        }
        System.out.println("Accepting connection");
        Socket s = ss.accept();
        System.out.println("Reading");
        InputStream is = s.getInputStream();
        byte[] b = new byte[10000];
        int blen = 0;
        int n;
        while((n = is.read(b, blen, b.length - blen)) > 0) {
            blen += n;
        }
        System.out.print("Received " + blen + " bytes from client:");
        for(int i = 0; i < blen; i++) System.out.print(" " + b[i]);
        System.out.println();
        System.out.println("Closing");
        is.close();
        s.close();
        ss.close();
   }
}
