implements HandshakeCompletedListener : SSL Server Socket « Network Protocol « Java






implements HandshakeCompletedListener

  

import javax.net.ssl.HandshakeCompletedEvent;
import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

class MyHandshakeListener implements HandshakeCompletedListener {
  public void handshakeCompleted(HandshakeCompletedEvent e) {
    System.out.println("Using cipher suite: " + e.getCipherSuite());
  }
}

public class Main {
  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();
    System.out.println("Just connected to " + socket.getRemoteSocketAddress());
  }
}

   
    
  








Related examples in the same category

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