public void begin(String server, int port) throws ParseException,
                IOException {

            this.server = server;
            this.port = port;
            authenticated = false;
            
            // Try to open a socket with server
            try {
                
                // Set keyStore and trustStore Paths and Passwords
                
                SSLSocketFactory sslsocketfactory = loadClientStores("KeyStore",
                        "hl6d1vF8kow63ca6l3t9bO8YWD6x8GkgsKb2x0DISwng428LnbFqRr"
                        + "uC1DrU2yk6deb883tYpgiw1a3gEQMDEshxArbr21XP2Y8v",
                        "TrustStore", "y5CSGUULYiXBg0i8k6W12GwuG23kuS7lYWPvHODi"
                        + "BNJshV55AqgL1ZnGjtfTS0LZsYjQDYmjClum2f25fPPtNvjEEwCX"
                        + "42OZ63Mj");
                socket = (SSLSocket) sslsocketfactory.createSocket(server, port);

                inputstream = socket.getInputStream();
                InputStreamReader inputstreamreader =
                        new InputStreamReader(inputstream);
                bufferedreader = new BufferedReader(inputstreamreader);

                outputstream = socket.getOutputStream();
                OutputStreamWriter outputstreamwriter =
                        new OutputStreamWriter(outputstream);
                bufferedwriter = new BufferedWriter(outputstreamwriter);
                socket.setSoTimeout(5000000);
            }
            catch (SocketException se) {
                ActivationServiceClient.log("Disconnected from server.");
                // Return if already failed 11 times after showing message
                if (connectCounts > 10) {
                    loginPanel("Please Login to continue.");
                    JOptionPane.showMessageDialog(ActivationServiceClient.this,
                        "Error connecting to the server.\n"
                            + "Please check your internet connection.",
                        "Error Message",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                }
                // Re-connect to the server if less than 11 attempts
                connectCounts++;
                // Wait for 5 seconds before reconnect
                try {
                    Thread.sleep(1000);
                }
                catch(InterruptedException ex) {
                    Thread.currentThread().interrupt();
                }
                finally {
                    // Begin connection
                    begin(server, port);
                    return;
                }
            }
            catch (SSLHandshakeException ssl) {
                ActivationServiceClient.log("Disconnected from server.");
                // Return if already failed 11 times after showing message
                if (connectCounts > 10){
                    JOptionPane.showMessageDialog(ActivationServiceClient.this,
                        "Unable to establish a connection to the server.\n"
                            + "Please check your internet connecton.",
                        "Error Message",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                }
                // Re-connect to the server if less than 11 attempts
                connectCounts++;
                // Wait for 5 seconds before reconnect
                try {
                    Thread.sleep(1000);
                }
                catch(InterruptedException ex) {
                    Thread.currentThread().interrupt();
                }
                finally {
                    // Begin Connection
                    begin(server, port);
                    return;
                }
            }
            catch (Exception exception) {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                exception.printStackTrace(new PrintStream(out));
                ActivationServiceClient.log(new String(out.toByteArray()));
                // Return if already failed 11 times after showing message
                if (connectCounts > 10){
                    JOptionPane.showMessageDialog(ActivationServiceClient.this,
                        "An error occurred please restart"
                            + " the application and try again.",
                        "Error Message",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                }
                // Re-connect to the server if less than 11 attempts
                connectCounts++;
                // Wait for 5 seconds before reconnect
                try {
                    Thread.sleep(1000);
                }
                catch(InterruptedException ex) {
                    Thread.currentThread().interrupt();
                }
                finally {
                    // Begin Connection
                    begin(server, port);
                    return;
                }
            }
            // Authenticate client once connected
            reconnectCounts = 0;
            connectCounts = 0;
            authenticate();
        }