How Do I Know When the “Handshake” Is Over?

The following code is a JSSE client application that uses the HandshakeCompletedListener interface to find out when a handshake is over.

import java.net.*;import java.io.*;import javax.net.*;import javax.net.ssl.*;class contact_server implements HandshakeCompletedListener{Socket SSLsoclu=null;          //client socketPrintWriter out=null;          //out streamBufferedReader in=null;        //in streamInputStreamReader ISR=null;String intrare=null;String iesire=null;BufferedReader message=null;  public contact_server(){}void send_message(){try{   SocketFactory SSLfabrica=SSLSocketFactory.getDefault();    SSLsoclu=SSLfabrica.createSocket("127.0.0.1",443);         ((SSLSocket)SSLsoclu).addHandshakeCompletedListener(this);  ((SSLSocket)SSLsoclu).startHandshake();         }catch(IOException e)       {       System.out.println("Error 1:"+e.getMessage());       System.exit(1);       }        try{      out=new PrintWriter(SSLsoclu.getOutputStream(),true);      ISR=new InputStreamReader(SSLsoclu.getInputStream());         in=new BufferedReader(ISR);                      while((intrare=in.readLine())!=null)       {           System.out.println("Server "+intrare);       message=new BufferedReader(new InputStreamReader(System.in));       System.out.flush();       System.out.print("Send:");       iesire=message.readLine();       if (iesire!=null)out.println(iesire);                                else break;       }      System.out.println("Connection canceled!!!");      out.close();      in.close();      message.close();      SSLsoclu.close();            }catch(IOException e)           {           System.out.println("Error 2:"+e.getMessage());           System.exit(1);           }  }  public void handshakeCompleted(HandshakeCompletedEvent e)     {     System.out.println(""Handshake" over!");     System.out.println(e.getCipherSuite());     }  }public class SSLClientSide{public static void main(String[] args){//put here your one keystore - this is just an exampleSystem.setProperty("javax.net.ssl.trustStore","SSLcert");System.setProperty("javax.net.ssl.trustStorePassword","e1002qa2");    contact_server t=new contact_server();    t.send_message();    }}
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a