Practical 1
Implementation of Stop and Wait Protocol and SlidingWindow Protocol.
1. Practical significance : Stop and Wait Protocol : It is the simplest flow control method. In
this, the sender will transmit one frame at a time to the receiver. The sender will stop and wait
for the acknowledgement from the receiver. This time (i.e. the time joining message transmitting
and acknowledgement receiving) is the sender’swaiting time, and the sender is idle during this
time. When the sender gets the acknowledgement (ACK), it will send the next data packet to the
receiver and wait for the disclosure again, and this process will continue as long as the senderhas
the data to send. While sending the data from the sender to the receiver, the data flow needs to be
controlled. If the sender is transmitting the data at a rate higher than the receiver can receive and
process it, the data will get lost. The Flow-control methods will help in ensuringthat the data
doesn't get lost. The flow control method will check that the senders send the dataonly at a rate
that the receiver can receive and process. The features of Stop and Wait Protocol are as follows −
● It is used in Connection-oriented communication.
● It offers error and flows control.
● It can be used in data Link and transport Layers.
● Stop and Wait ARQ executes Sliding Window Protocol with Window Size 1 Sliding Window
Protocol : Sliding window protocols are data link layer protocols for reliable and sequential
delivery of data frames. The sliding window is also used in Transmission Control Protocol. In
this protocol, multiple frames can be sent by a sender at a time before receiving an
acknowledgment from the receiver. The term sliding window refers to the imaginary boxes
tohold frames. Sliding window method is also known as windowing. Working Principle In these
protocols, the sender has a buffer called the sending window and the receiver has buffercalled the
receiving window. The size of the sending window determines the sequence number of the
outbound frames. If thesequence number of the frames is an n-bit field, then the range of
sequence numbers that can beassigned is 0 to 2𝑛−1. Consequently, the size of the sending
window is 2𝑛−1. Thus in order toaccommodate a sending window size of 2𝑛−1, a n-bit sequence
number is chosen. The sequence numbers are numbered as modulo-n. For example, if the
sending window size is4, then the sequence numbers will be 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, and so on.
The number of bits in the sequence number is 2 to generate the binary sequence 00, 01, 10, 11.
The size of the receiving window is the maximum number of frames that the receiver can
acceptat a time. It determines the maximum number of frames that the sender can send before
receiving acknowledgment. 2. Relevant Program Outcomes : PO1,PO2,PO3, PO5 3.
Competency and practical skills :
The practical is expected to develop the fallowing skills :
1. Extract the knowledge from different Networking protocols and their implementations.
2. Ability to work on C/Java compilers.
4.Prerequisites : 1. Student should have knowledge on Computer Networks.
5. Resources required : S.No Name of the Resource Broad Specification(Approx.)
1 Computer System
1. Processor – 2GHz
2. RAM – 4GB
3. Hard-Drive Space – 20GB
4. VGA with 1024×768 screen resolution (exact hardware requirement will depend upon the
distribution that we choose to work with)
5. JDK(JAVA DEVELOPMENT KIT)
6. Precautions:
1. Check Whether the computer is getting proper power or not.
2. Ensure the keyboard, mouse and monitor are properly working.
3. Ensure that there are no power fluctuations while executing the program.
4. Safe working conditions help prevent injury to people and damage to computer equipment.
5. A safe work space is clean, organized, and properly lighted. Everyone must understand and
follow safety procedures.
6. Follow electrical safety guidelines to prevent electrical fires, injuries, and fatalities in the
home and the workplace. Power supplies and CRT monitors contain high voltage.
7. Algorithm/circuit/Diagram/Description: i)
Stop-and-wait ARQ: RECEIVER(SERVER):
import java.io.*;
import java.net.*;
import java.util.*;
public class receiver { public static void main(String args[]) { String h="Serverhost";
int q=5000; int i;
try { ServerSocket ss2; ss2 = new ServerSocket(8000);
Socket s1 =ss2.accept();
DataInputStream dd1= new DataInputStream(s1.getInputStream());
Integer i1 =dd1.read();
for(i=0;i<=sws-1) { System.out.println("Enter "+nf+" Messages to be send\n");
for(i=1;i<=nf;i++) { sbuff[sptr]=in.readLine();
p.println(sbuff[sptr]);
sptr=++sptr%8; } sws-=nf; System.out.print("Acknowledgment received");
ano=Integer.parseInt(in1.readLine());
System.out.println(" for "+ano+" frames"); sws+=nf; }
else
{ System.out.println("The no. of frames exceeds window size"); break;
System.out.print("\nDo you wants to send some more frames : ");
ch=in.readLine(); p.println(ch);
while(ch.equals("yes")); s.close();
RECEIVER PROGRAM import java.net.*;
import java.io.*;
class slidreceiver { public static void main(String a[])throws Exception
Socket s=new Socket(InetAddress.getLocalHost(),10);
DataInputStream in=new DataInputStream(s.getInputStream());
PrintStream p=new PrintStream(s.getOutputStream());
int i=0,rptr=-1,nf,rws=8;
String rbuf[]=new String[8];
String ch;
System.out.println();
do
nf=Integer.parseInt(in.readLine());
if(nf<=rws-1)
for(i=1;i<=nf;i++)
rptr=++rptr%8;
rbuf[rptr]=in.readLine();
System.out.println("The received Frame " +rptr+" is : "+rbuf[rptr]);
rws-=nf;
System.out.println("\nAcknowledgment sent\n");
p.println(rptr+1);
rws+=nf;
else
break;
ch=in.readLine();
while
(ch.equals("yes"));
9. Sample output:
//SENDER OUTPUT
Enter the no. of frames :
4 Enter
4 Messages to be send
hiii how r u
i am fine how is everyone
Acknowledgment received for 4 frames
Do you wants to send some more frames : no
RECEIVER OUTPUT The received Frame 0 is : hiii
The received Frame
1 is : how r u The received Frame
2 is : i am fine The received Frame
3 is : how is everyone
Acknowledgment sent 10.