To write a python program to perform stop and wait protocol
- Start the program.
- Get the frame size from the user
- To create the frame based on the user request.
- To send frames to server from the client side.
- If your frames reach the server it will send ACK signal to client
- Stop the Program
import time
def send_frame(frame):
print(f"Sending frame: {frame}")
time.sleep(1) # Simulating transmission time
return True
def receive_ack():
time.sleep(1) # Simulating transmission time
return True
def stop_and_wait_protocol(frame_size):
for frame_number in range(frame_size):
frame = f"Frame {frame_number}"
while not send_frame(frame):
print("Timeout occurred. Resending frame.")
print(f"Frame {frame_number} sent successfully.")
ack_received = receive_ack()
while not ack_received:
print("Timeout occurred. Resending frame.")
ack_received = receive_ack()
print(f"Acknowledgment received for Frame {frame_number}.\n")
print("Data transmission completed.")
if __name__ == "__main__":
frame_size = int(input("Enter the frame size: "))
stop_and_wait_protocol(frame_size)
Thus, python program to perform stop and wait protocol was successfully executed.