Code example for SSLSocketFactory

Methods: createSocket

0
    PrintWriter output;
 
    public EmailService(String server, int port) {
	try { 
	    SSLSocketFactory sslsocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
	    socket = (SSLSocket) sslsocketFactory.createSocket(server, port);
	    input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
 
	    // After each println you MUST flush the buffer, or it won't work 
	    // properly. 
	    // The true argument makes an automatic flush after each println. 
	    output = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
	} catch (UnknownHostException e) {
	    e.printStackTrace();
	} catch (IOException e) {
	    e.printStackTrace();
	} 
    } 
 
    public String readOneLine() throws IOException {
	return input.readLine();