public void authenticate() throws ParseException, SQLiteException, IOException {
        
        String string;
        JSONObject json;
        
        // If not authenticated, commence        
        if (!authenticated) {
                
            try {
                // Keep reading messages from the server
                while ((string = bufferedreader.readLine()) != null) {
                    
                    // Log message
                    //UpdateServiceClient.log(string);
                    
                    json = (JSONObject)new JSONParser().parse(string);
                    JSONObject reply = new JSONObject();
                    String message = (String) json.get("message");

                    // Server is asking to authenticate
                    if (message.equals("authenticate")) {
                        UpdateServiceClient.log("System asking for"
                                + " authorization.");
                        // Ask server to read your Machine ID and
                        // authenticate you
                        reply.put("message", "readKey");
                        reply.put("machineId", machineId);
                        reply.put("gameId", gameId);
                        reply.put("version", version);
                        bufferedwriter.write(reply.toJSONString() + "\r\n");
                        bufferedwriter.flush();
                    } // Server could not authenticate you, subscription expired?
                    else if (message.equals("authenticationFailed")) {
                        UpdateServiceClient.log("Authentication Failed.");
                        break;
                    } // Server has authenticated you
                    else if (message.equals("authenticated")) {
                        UpdateServiceClient.log("Authenticated.");
                        authenticated = true;
                        break;
                    } // Could not understand server reply
                    else {
                        break;
                    }
                }
                
            }
            catch (SocketException se) {
                UpdateServiceClient.log("Socket Exception, re-establishing"
                        + " connection.");
                reconnect();
                return;
            }
            catch (SSLHandshakeException ssl) {
                UpdateServiceClient.log("SSL Exception, re-establishing"
                        + " connection");
                reconnect();
                return;
            }
            catch (IOException e) {
                UpdateServiceClient.log("IO Exception, re-establishing"
                        + " connection.");
                reconnect();
                return;
            }
            catch (Exception e) {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                e.printStackTrace(new PrintStream(out));
                UpdateServiceClient.log(new String(out.toByteArray()));
            }
        }
    }