List of usage examples for javax.net.ssl SSLServerSocketFactory getDefault
public static ServerSocketFactory getDefault()
From source file:SecureServer.java
public static void main(String[] args) throws Exception { ServerSocketFactory ssf = SSLServerSocketFactory.getDefault(); SSLServerSocket ss = (SSLServerSocket) ssf.createServerSocket(98999); Socket sock = ss.accept();/*ww w . j av a 2 s. com*/ ss.close(); OutputStream rawOut = sock.getOutputStream(); PrintWriter out = new PrintWriter(new OutputStreamWriter(rawOut)); out.println(new java.util.Date().toString()); out.flush(); sock.close(); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(8080); while (true) { try {//w w w .jav a 2 s. c o m Socket s = ss.accept(); OutputStream out = s.getOutputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String line = null; while (((line = in.readLine()) != null) && (!("".equals(line)))) { System.out.println(line); } StringBuffer buffer = new StringBuffer(); buffer.append("<HTML><HEAD><TITLE>HTTPS Server</TITLE></HEAD>\n"); buffer.append("<BODY>\n<H1>Success!</H1></BODY></HTML>\n"); String string = buffer.toString(); byte[] data = string.getBytes(); out.write("HTTP/1.0 200 OK\n".getBytes()); out.write(new String("Content-Length: " + data.length + "\n").getBytes()); out.write("Content-Type: text/html\n\n".getBytes()); out.write(data); out.flush(); out.close(); in.close(); s.close(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(PORT); Socket s = ss.accept();/* ww w. j a v a2 s. c om*/ BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String line = null; while (((line = in.readLine()) != null)) { System.out.println(line); } in.close(); s.close(); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); SSLServerSocket ss = (SSLServerSocket) ssf.createServerSocket(8080); ss.setNeedClientAuth(true);// www . j av a 2s.c o m while (true) { try { Socket s = ss.accept(); OutputStream out = s.getOutputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String line = null; while (((line = in.readLine()) != null) && (!("".equals(line)))) { System.out.println(line); } System.out.println(""); StringBuffer buffer = new StringBuffer(); buffer.append("<HTML>\n"); buffer.append("<HEAD><TITLE>HTTPS Server</TITLE></HEAD>\n"); buffer.append("<BODY>\n"); buffer.append("<H1>Success!</H1>\n"); buffer.append("</BODY>\n"); buffer.append("</HTML>\n"); String string = buffer.toString(); byte[] data = string.getBytes(); out.write("HTTP/1.0 200 OK\n".getBytes()); out.write(new String("Content-Length: " + data.length + "\n").getBytes()); out.write("Content-Type: text/html\n\n".getBytes()); out.write(data); out.flush(); out.close(); in.close(); s.close(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(8080); String[] suites = serverSocket.getSupportedCipherSuites(); for (int i = 0; i < suites.length; i++) { System.out.println(suites[i]); }/*from w ww . ja v a2 s . co m*/ serverSocket.setEnabledCipherSuites(suites); String[] protocols = serverSocket.getSupportedProtocols(); for (int i = 0; i < protocols.length; i++) { System.out.println(protocols[i]); } SSLSocket socket = (SSLSocket) serverSocket.accept(); socket.startHandshake(); System.out.println(socket.getRemoteSocketAddress()); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(5432); while (true) { Socket s = ss.accept();//from w w w . j av a2 s . c o m PrintStream out = new PrintStream(s.getOutputStream()); out.println("Hi"); out.close(); s.close(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { int port = 443; ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault(); ServerSocket ssocket = ssocketFactory.createServerSocket(port); Socket socket = ssocket.accept(); InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); // Read from in and write to out... in.close();// w ww . ja v a 2s.c om out.close(); }
From source file:SSLSimpleServer.java
public static void main(String[] args) throws Exception { ServerSocketFactory ssf = SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(9096); System.out.println("Ready..."); while (true) { new SSLSimpleServer(ss.accept()).start(); }//from w w w . j av a 2 s . c o m }
From source file:MainClass.java
public static void main(String args[]) throws Exception { System.setProperty("javax.net.ssl.keyStore", "mykeystore"); System.setProperty("javax.net.ssl.keyStorePassword", "wshr.ut"); SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(5432); while (true) { Socket s = ss.accept();//from w ww . j a v a2 s . c o m PrintStream out = new PrintStream(s.getOutputStream()); out.println("Hi"); out.close(); s.close(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { ServerSocketFactory ssf = SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(9096); while (true) { new SSLSimpleServer(ss.accept()).start(); }//from w w w. ja va 2 s . c o m }