Professional Documents
Culture Documents
Lab 3 CN
Lab 3 CN
Lab 3 CN
2100290110059
COMPUTER NETWORK A2 BATCH
COMPUTER NETWORKS EXPERIMENT LAB 3
Implement the simplex and stop and wait protocols with any
programming language.
You can run this code to see how the sender sends frames and the receiver
acknowledges them in a stop-and-wait manner.
CODE:
import time
def sender(message):
seq_num = 0
while True:
ack = receiver(seq_num)
if ack == "ACK":
HARSH KUMAR
2100290110059
COMPUTER NETWORK A2 BATCH
print("Sender: Frame", seq_num, "successfully received by receiver")
if message:
else:
break
else:
def receiver(expected_seq_num):
# Example usage:
message = [1, 2, 3, 4, 5]
sender(message)
OUTPUT:
Sender: Sending frame with sequence number 0
This output demonstrates the stop-and-wait protocol in action. The sender sends frames with
sequence numbers 0 and 1 alternately, and the receiver acknowledges each frame with the
corresponding sequence number. If the sender does not receive an acknowledgment, it resends
the frame.