public void checkMessages(){
        if(debug){
            System.out.println("Running");
        }
        //Run in a continues loop
        while(running){
            //Don't check for new messages if connectedTo is not set yet
            if(connectedTo!=null&&!connectedTo.equals("")){
                String receivedMessage = com.receiveNewChat(connectedTo,username);
                if(debug){
                    System.out.println(receivedMessage);
                }
                if(!receivedMessage.equals("0")){
                    if(debug){
                        System.out.println(receivedMessage);
                    }
                    //Update chat history
                    chatHistory.setText(chatHistory.getText()+"<br>"+connectedTo+": "+receivedMessage);
                }
            }
            try
            {
                /*
                 * Put the thread to sleep to make sure that the new messages are check
                 * with an interval of DELAY
                 */
                Thread.sleep(DELAY);

            }catch (InterruptedException ie)
            {
                System.out.println(ie.getMessage());
            }
        }
    }