0% found this document useful (0 votes)
14 views4 pages

Go Back N

This document describes a Go Back N protocol implementation between a server and client. The server receives data from the client, can choose to send an ACK or NACK, and the client resends packets if it receives a NACK. The client sends data packets to the server and resends packets if it receives a NACK acknowledgment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Go Back N

This document describes a Go Back N protocol implementation between a server and client. The server receives data from the client, can choose to send an ACK or NACK, and the client resends packets if it receives a NACK. The client sends data packets to the server and resends packets if it receives a NACK acknowledgment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

GO BACK N

SERVER :

Program :

import socket

HOST = '127.0.0.1' # Standard loopback interface address (localhost)


PORT = 65432 # Port to listen on (non-privileged ports are > 1023)

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:


s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
recv_data = conn.recv(1024)
if(recv_data == "q"):
s.close()
exit(0)
else:
print("\n1.SEND ACK\n2.DO NOT SEND ACK\n")
opt=input("Enter Option : ")
if(opt=="1"):
send_data="ACK"
print("\n RECEIVED DATA = ",recv_data )
i=input("Enter 1 to continue : ")
else:
send_data="NACK";
conn.sendall(send_data.encode())
Output :
CLIENT :

Program :

import socket

HOST = '127.0.0.1' # The server's hostname or IP address


PORT = 65432 # The port used by the server

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s :


s.connect((HOST, PORT))
send_data = list()
while(1) :
pkt = int(input("Enter the Number of Packets (0 to exit) : "))
if pkt == 0 :
s.sendall("q".encode())
s.close()
exit(0)
nack = 100
resend = 0
i=0
while(i < pkt) :
if resend == 1 :
nack = 100
print("Resending Packet", i+1, ":", send_data[i])
opt = input("Enter 1 to Continue : ")
else :
print("Enter the Packet : ", i+1)
s_data = input()
send_data.append(s_data)
s.sendall(send_data[i].encode())
recv_data = s.recv(1024)
if(recv_data == "NACK") :
print("Received Negative Acknowledgement")
if nack > i :
nack = i
if (i+1) >= pkt :
resend = 1
i = nack
continue
i=i+1
print("Retransmission Completed”)
Output :

You might also like