About the SSL | developer.brewmp.com About the SSL | developer.brewmp.com

Developer

About the SSL

Forums:

Hi Guys,

 

Who can help you.

I'm developing a SSL client in Brew. But I don't know how to do it.

Is there any reference code for it? 

 

The java sample code are the following:

public class MNSSLClient {

 

    public static void main(String[] args) {

 

        try{

            File f = new File("D:\\Dropbox\\Emporia\\emporiaME\\Persistant Connection Test\\client.truststore.ks");

 

            if(f.exists()) {

                System.setProperty("javax.net.ssl.trustStore", f.getAbsolutePath());

//                System.setProperty("javax.net.debug", "ssl");

 

                System.out.println("Key store loaded");

            }

 

            System.out.println("Trying to open SSL socket");

 

            SocketFactory socketFactory = SSLSocketFactory.getDefault();

            //Socket socket = socketFactory.createSocket("ec2-46-137-71-192.eu-west-1.compute.amazonaws.com", 443);

            Socket socket = socketFactory.createSocket("ec2-46-137-6-20.eu-west-1.compute.amazonaws.com", 443);

            socket.setKeepAlive(true);

 

            System.out.println("Socket opened from " 

                    + socket.getLocalAddress() + ":" + socket.getLocalPort() + " to "

                    + socket.getInetAddress() + ":" + socket.getPort()

            );

 

            System.out.println("Open time: " + new Date() );

            System.out.println("Keep alive: " + socket.getKeepAlive() );

 

            ObjectOutputStream writer = new ObjectOutputStream(socket.getOutputStream());

            ObjectInputStream reader = new ObjectInputStream(socket.getInputStream());

            System.out.println("Receiving bytes");

            byte[] inbuf = new byte[255];

            int bRead;

            while( (bRead = reader.read(inbuf)) > 0){

                System.out.println(new Date() + " (" + bRead + ") : " + new String(inbuf, 0, bRead));

            }

            reader.close();

 

        } catch (Exception e) {

            //e.printStackTrace();

        }

    }

}

Thank you very much!Tom.Song