Пример #1
0
def clientMain(serverIP, serverPort):
    '''Starts the client
    
    Args:
        - serverIP -- ip address of server to connect to
        - serverPort -- port on which the server is listening
    
    '''

    #initialization of values
    #timeName = time.strftime("%d%b%Y%H%M%S", time.localtime()) # a unique id created from the time when the script starts 
    messageQueue = multiprocessing.Queue() # the queue where all log messages are written to.
    logControlValue = multiprocessing.Value('i',int(True)) #A boolean indicating the the logging process should continue to run. There is no type for bool, so we use int
    resultsDirectory, logsDirectory = UtilityFunctions.initializeClientFolderStructure() #directories where results and logs should be stored respectively
    UtilityFunctions.deleteContentsOfDirectory('./client/temp')
    #-------------start logging module
    loggingProcess = multiprocessing.Process(target = LoggingModule.log, args=(logControlValue,messageQueue,logsDirectory))
    loggingProcess.start()
    
    #communicate with server    
    
    handleConnection(messageQueue, serverIP,serverPort,resultsDirectory)
    
    
    #exit note that we only get here once the server closes the connection
    logControlValue.value = int(False)
    loggingProcess.join()
    sys.exit(0)