def receiveFromSender(): while True: print(15 * '-') # Receive the frame from the sender stored_frame = sockSenderReceive.recv(1024).decode() print('Frame received from sender ' + stored_frame) # Insert error and other stuffs here # Send frame with a probability p p = random.randint(0, probas) if (p >= randSendF or len(stored_frame) < 8): # Ending marker should always be sent # Introduce error here with a probability p2 = random.randint(0, probas) if (p2 <= randErrF and len(stored_frame) >= 8): print("Introducing error") stored_frame = co.ins_error(stored_frame, [1]) # Send the frame to the receiver print('Sending frame to receiver ' + stored_frame) # Add sleep here # time.sleep(7) co.send_frame(stored_frame, receiverSend) print('Sent frame ' + stored_frame) if (stored_frame == '#'): break # Dont Send the frame else: print('Not sending frame') print(15 * '-')
def receiveAckFromReceiver(): while True: print(15 * '=') # Wait ack from receiver ack = sockReceiverReceive.recv(1024).decode() print('Ack received from receiver ' + ack) if (ack == '#'): break # Insert error and other stuffs here # send the frame with a probability p = random.randint(0, probas) if (p >= randSendAck): # Introduce error here with a probability p2 = random.randint(0, probas) if (p2 <= randErrAck): print("Introducing error") ack = co.ins_error(ack, [1]) print('Sending ack to sender ' + ack) # Add sleep here # time.sleep(7) # Send the ack to the sender co.send_frame(ack, senderSend) else: print('Not sending acknowledgement') print(15 * '=')
print(15 * '-') # Receive the frame from the sender stored_frame = sockSenderReceive.recv(1024).decode() print('Frame received from sender ' + stored_frame) # Insert error and other stuffs here # Send frame with a probability p p = random.randint(0, probas) print(p) if (p >= randSendF or len(stored_frame) < 8): # Ending marker should always be sent # Introduce error here with a probability p2 = random.randint(0, probas) if (p2 <= randErrF and len(stored_frame) >= 8): print("Introducing error") stored_frame = co.ins_error(stored_frame, [1]) # Send the frame to the receiver print('Sending frame to receiver ' + stored_frame) # Add sleep here time.sleep(2) co.send_frame(stored_frame, receiverSend) print('Sent frame ' + stored_frame) # Dont Send the frame else: print('Not sending frame') continue try: # Wait ack from receiver