Secure Communication with JSSE : SSL Server Socket « Network Protocol « Java






Secure Communication with JSSE

  
 
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;

public class Main {
  public static void main(String args[]) throws Exception {
    SocketFactory factory = SSLSocketFactory.getDefault();
    Socket socket = factory.createSocket("127.0.0.1", 8080);

    OutputStream outputStream = socket.getOutputStream();
    PrintWriter out = new PrintWriter(outputStream);
    out.print("GET / HTTP/1.0\r\n\r\n");
    out.flush();
    InputStream inputStream = socket.getInputStream();
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    BufferedReader in = new BufferedReader(inputStreamReader);

    String line;
    while ((line = in.readLine()) != null) {
      System.out.println(line);
    }
    out.close();
    in.close();
    socket.close();

  }
}

   
    
  








Related examples in the same category

1.Creating an SSL Client Socket
2.Creating an SSL Server Socket
3.Secure Login based on SSL Server Socket
4.Simple Client for secure Socket
5.Simple server for Secure socket
6.Secure Server
7.SSL Server Demo
8.Secure Client
9.A simple single-threaded proxy server
10.implements HandshakeCompletedListener
11.Cipher Socket