Beispiel #1
0
def main():
    # Network variables
    dilationFactor = 5
    networkSize = 3

    print("Hello from the Network Mode")
    transmission_init = True
    teamNumber = int(raw_input("What team are you?"))
    team = Team(teamNumber, UDP=False, dilationFactor=dilationFactor, networkSize=networkSize)
    timeout = random.uniform(5, 10)
    startTime = time.time()
    timePassed = 0
    while not team.checkFinished() and timePassed < 120:
        result, controlPacket = team.waitControl(timeout)
        # If result is 0 it means that timeout passed
        if result == 1:
            transmission_init = False
            team.receiver(controlPacket)
            timeout = (0.05 + random.uniform(0, 0.01))*dilationFactor
        if team.nextPlayer:
            print("I am the next player, sender mode...")
            if transmission_init:
                transmission_init = False
                team.sender(0)
            else:
                team.sender(0.001*dilationFactor)
            timeout = (0.1 + random.uniform(0, 0.02))*dilationFactor
        timePassed = time.time() - startTime

    if timePassed > 120:
        print("Timeout!")
    else:
        print("Transmission complete. Time elapsed: {}".format(timePassed))
Beispiel #2
0
def main_nm():
    # Network variables
    dilationFactor = 7
    networkSize = 4

    logfile = open("/home/pi/Documents/MTP-Group-C/Final_Code/logFile_NM.txt",
                   "wb")
    logfile.write("Hello from the Network Mode")
    logfile.close()

    print("Hello from the Network Mode")
    transmission_init = True
    teamNumber = 2
    team = Team(teamNumber,
                UDP=False,
                dilationFactor=dilationFactor,
                networkSize=networkSize)
    timeout = random.uniform(5, 10)
    startTime = time.time()
    timePassed = 0
    while not team.checkFinished() and timePassed < 120:
        result, controlPacket = team.waitControl(timeout)
        # If result is 0 it means that timeout passed
        if result == 1:
            transmission_init = False
            team.receiver(controlPacket)
            timeout = (0.05 + random.uniform(0, 0.01)) * dilationFactor
        if team.nextPlayer:
            print("I am the next player, sender mode...")
            if transmission_init:
                transmission_init = False
                team.sender(0)
            else:
                team.sender(0.001 * dilationFactor)
            timeout = (0.1 + random.uniform(0, 0.02)) * dilationFactor
        timePassed = time.time() - startTime

    if timePassed > 120:
        print("Timeout!")
    else:
        print("Transmission complete. Time elapsed: {}".format(timePassed))