Example usage for javax.net.ssl SSLSocketFactory getDefault

List of usage examples for javax.net.ssl SSLSocketFactory getDefault

Introduction

In this page you can find the example usage for javax.net.ssl SSLSocketFactory getDefault.

Prototype

public static SocketFactory getDefault() 

Source Link

Document

Returns the default SSL socket factory.

Usage

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 5432);
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    String x = in.readLine();//from  www.  j a v a 2 s.c o  m
    System.out.println(x);
    in.close();

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = sf.createSocket(HOST, PORT);
    OutputStream out = s.getOutputStream();
    out.write("\nConnection established.\n\n".getBytes());
    out.flush();/* w  w w .  j  a va2 s . c  om*/
    int theCharacter = 0;
    theCharacter = System.in.read();
    while (theCharacter != '~') // The '~' is an escape character to exit
    {
        out.write(theCharacter);
        out.flush();
        theCharacter = System.in.read();
    }

    out.close();
    s.close();
}

From source file:SSLSimpleClient.java

public static void main(String[] args) throws Exception {
    SocketFactory sf = SSLSocketFactory.getDefault();
    Socket s = sf.createSocket(args[0], Integer.parseInt(args[1]));

    BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
    PrintWriter pw = new PrintWriter(s.getOutputStream());
    pw.println("from java2s.");
    pw.flush();//w ww  .  j  a  v a 2 s . co  m
    System.out.println(br.readLine());
    s.close();
}

From source file:SecureClient.java

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();//from   www . j  a va2 s. co  m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int port = 443;
    String hostname = "hostname";
    SocketFactory socketFactory = SSLSocketFactory.getDefault();
    Socket socket = socketFactory.createSocket(hostname, port);

    InputStream in = socket.getInputStream();
    OutputStream out = socket.getOutputStream();

    // Read from in and write to out...

    in.close();/*from w  ww .j  a  v  a 2  s  .c o m*/
    out.close();
}

From source file:Main.java

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();/*from  w  ww.  j a  v a2s .co  m*/
    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();

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    System.setProperty("javax.net.ssl.trustStore", "clienttrust");
    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 8888);

    OutputStream outs = s.getOutputStream();
    PrintStream out = new PrintStream(outs);
    InputStream ins = s.getInputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(ins));

    out.println("Hi,How are u!");
    out.println("");
    String line = null;/* w  ww .j  a  v a2s . c  om*/
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }

    in.close();
    out.close();
}

From source file:MyHandshakeListener.java

public static void main(String[] args) throws Exception {
    SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
    SSLSocket socket = (SSLSocket) factory.createSocket("127.0.0.1", 8080);
    String[] suites = socket.getSupportedCipherSuites();
    socket.setEnabledCipherSuites(suites);
    socket.addHandshakeCompletedListener(new MyHandshakeListener());
    socket.startHandshake();/*from   www.  j  a  va2  s  . c o  m*/
    System.out.println("Just connected to " + socket.getRemoteSocketAddress());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    FileOutputStream fouts = null;
    System.setProperty("javax.net.ssl.trustStore", "clienttrust");
    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 5432);

    OutputStream outs = s.getOutputStream();
    PrintStream out = new PrintStream(outs);
    InputStream ins = s.getInputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(ins));

    out.println(args[0]);//ww w  .  j  a v a  2 s .  co  m
    fouts = new FileOutputStream("result.html");
    //  fouts = new FileOutputStream("result.gif");
    int kk;
    while ((kk = ins.read()) != -1) {
        fouts.write(kk);
    }
    in.close();
    fouts.close();
}

From source file:Test.java

  public static void main(String[] args) throws Exception {

  SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory
      .getDefault();//from w  w w  .j a  v  a  2s  .c  om
  SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
      "localhost", 9999);

  InputStreamReader inputStreamReader = new InputStreamReader(System.in);
  BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

  OutputStream outputStream = sslSocket.getOutputStream();
  OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
  BufferedWriter bufferedwriter = new BufferedWriter(outputStreamWriter);

  String line = null;
  while ((line = bufferedReader.readLine()) != null) {
    bufferedwriter.write(line + '\n');
    bufferedwriter.flush();
  }
}