def connect_to_server():
    '''
    Starts a connection to the server 
    '''
    try:
        
        secure_utils.clear_screen()  # clear screen for nice output
        secure_utils.draw_client_logo()  # 
        
        my_client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        my_client_socket.connect((HOST_NAME, PORT_NUMBER))

        print_welcome_message(socket.gethostname(), my_client_socket.getsockname()[0])
    
        # wait to receive server's public key . WILL RETURN NO KEYS IF SERVER HAS BANNED YOU FROM CONNECTING
        (publicKeyTuple, privateKeyTuple) = exchange_keys_with_server(my_client_socket)
         
        # checks whether server accepted or refused connection. RETURNS NONE IF BANNED
        if((publicKeyTuple, privateKeyTuple) == ((None, None), (None, None))):
            my_client_socket.close()  # close the connection or session as you cannot carry on.

        else:  # begin interaction with other party.
            
            print '\n\033[1;42m*******Type your message below and hit enter to send. Type \'EXIT\' to end conversation.*******\033[1;m\n'
        
            ReadAndDecryptThread = ThreadManager('read', my_client_socket, publicKeyTuple, privateKeyTuple)  # Thread for reading in data and decrypting
            WriteAndEncryptThread = ThreadManager('write', my_client_socket, publicKeyTuple, privateKeyTuple)  # Thread for writing data and encrypting


            ReadAndDecryptThread.start()
            WriteAndEncryptThread.start()

            ReadAndDecryptThread.join()
            print '[+] Your partner has left the conversation. Press any key to continue...\n'

            # stop the write thread
            WriteAndEncryptThread.stop_write_loop()
            WriteAndEncryptThread.join()
    

            # shut down client connection
            secure_utils.display_processing_cursor('Shutting client down...')

    except socket.error as socket_error:
        secure_utils.clear_screen()
        print socket_error[1] + "\n"
        raw_input("Press [ENTER] To Return To The Main Menu...\n")
        return
        pass
def display_client_menu():
    
    '''
    Displays a program menu for user to choose an option
    
    '''

    try:
        # Clears the screen
        secure_utils.clear_screen()
        while True:
            # Display My Logo
            secure_utils.draw_client_logo()
            print '----------------------------------\n'
            print'1.  Set Host Name/IP To Use\n2.  Set Port Number To Use\n3.  Connect To Secure Chat Session\n4.  Program Information\n99. Exit Program\n'
            print '----------------------------------\n'
            user_chosen_option = raw_input('Enter an option >> ')
            secure_utils.clear_screen()
            
            if(user_chosen_option == '1'):
                set_host_name()
            elif(user_chosen_option == '2'):
                set_port_number()
            elif(user_chosen_option == '3'):
                connect_to_server()
            elif(user_chosen_option == '4'):
                secure_utils.program_info()
            elif(user_chosen_option == '5'):
                print "Coming Soon"
            elif(user_chosen_option == '6'):
                print "Coming Soon"
            elif(user_chosen_option == '98'):
                print "Coming Soon"
            elif(user_chosen_option == '99'):
                break
            else:
                print('[--] ERROR: Invalid Option.')
                raw_input("Press [ENTER] To Return To The Main Menu...\n")
            secure_utils.clear_screen()
                
    except KeyboardInterrupt:
        print'[--] CTRL+C Pressed.'
    except Exception, e:
        print'[--] ERROR: %s' % str(e)