The important part of the code is the first several lines. I want to know how to return after a certain amount of time. I know Timer calls a function after some time but I dont know how to return with it.
def rdt_rcv(conn, flag):
t2 = threading.Timer(5.0, rdt_rcv, return, [0, 0, 0, 0])
t2.start()
# if timeout, return
#return None, None, None, None
field1 = conn.recv(BUFFER_SIZE)
field1 = int(field1)
field2 = conn.recv(BUFFER_SIZE)
field2 = int(field2)
if field2 != 0:
global ACK_received
ACK_received = 1
field3 = (conn.recv(BUFFER_SIZE))
field3 = int(field3)
field4 = (conn.recv(BUFFER_SIZE))
field4 = int(field4)
# stop timer
t2.cancel()
return field1, field2, field3, field4