Advertisement
Chiddix

SSL

Sep 23rd, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. public class SSLServer {
  2.  
  3.     public static void main(String[] args) {
  4.         try {
  5.             int port = 443;
  6.             ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();
  7.             ServerSocket ssocket = ssocketFactory.createServerSocket(port);
  8.  
  9.             // Listen for connections
  10.             Socket socket = ssocket.accept();
  11.  
  12.             // Create streams to securely send and receive data to the client
  13.             InputStream in = socket.getInputStream();
  14.             OutputStream out = socket.getOutputStream();
  15.  
  16.             // Read from in and write to out...
  17.  
  18.             // Close the socket
  19.             in.close();
  20.             out.close();
  21.         } catch(IOException e) {
  22.             e.printStackTrace();
  23.         }
  24.     }
  25. }
  26.  
  27. public class SSLClient {
  28.  
  29.     public static void main(String[] args) {
  30.         try {
  31.             int port = 443;
  32.             String hostname = "hostname";
  33.             SocketFactory socketFactory = SSLSocketFactory.getDefault();
  34.             Socket socket = socketFactory.createSocket(hostname, port);
  35.  
  36.             // Create streams to securely send and receive data to the server
  37.             InputStream in = socket.getInputStream();
  38.             OutputStream out = socket.getOutputStream();
  39.  
  40.             // Read from in and write to out...
  41.  
  42.             // Close the socket
  43.             in.close();
  44.             out.close();
  45.         } catch (IOException e) {
  46.             e.printStackTrace();
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement