Sliding Window Protocol
Sliding Window Protocol
Khivsara
Asst Prof.
Computer Dept
SNJB’s KBJ COE,Chandwad
Sliding window protocols are used where Reliable In-
order delivery of packets is required, & such as in the
Data Link Layer (OSI model) in the Transmission
Control Protocol(TCP).
noiseless
(error-free)
channels
noisy (error-
creating)
channels
Figure Taxonomy of protocols
11.4
Let us first assume we have an ideal channel in
which no frames are lost, duplicated, or
corrupted.
11.7
NOISY CHANNELS (Sliding Window Protocol)
11.8
Note
11.9
Noiseless channels are nonexistent, so we need to add error
control to our protocols.
If the timer expires and there is no ACK for the sent frame,
the frame is resent, the copy is held, and the timer is
restarted.
Since an ACK frame can also be corrupted
and lost, it too needs redundancy bits
and a sequence number.
11.14
Figure Flow diagram for Stop and Wait ARQ
11.15
Go-Back-N ARQ is a specific instance of the automatic
repeat request (ARQ) protocol, in which the sending
process continues to send a number of frames specified
by a window size even without receiving
an acknowledgement (ACK) packet from the receiver.
Once the sender has sent all of the frames in its window, it will
detect that all of the frames since the first lost frame
are outstanding, and will go back to the sequence number of
the last ACK it received from the receiver process and fill its
window starting with that frame and continue the process over
again.
Figure 11.14 Design of Go-Back-N ARQ
Figure 11.16 Flow diagram for Example 11.6
Concept of Selective Repeat
Selective Repeat is part of the automatic repeat-request
(ARQ).
With selective repeat, the sender sends a number of
frames specified by a window size even without the need
to wait for individual ACK from the receiver as in go-
back-n ARQ.
The receiver may selectively reject a single frame, which
may be retransmitted alone;
this contrasts with other forms of ARQ, which must send
every frame from that point again.
The receiver accepts out-of-order frames and buffers
them.
The sender individually retransmits frames that have
timed out.
Comparison of Go-back-n (fig. a) & Selective
Repeat (Fig. b)
Data Communication
Use GBN or SR?
If errors low, might use GBN.
If errors high, might use SR.
If bandwidth cheap, might use GBN.
If bandwidth costly, might use SR.
Program in Java for
Sliding Window
Protocol
Sender side
&
Receiver Side
Sender side
import java.net.*;
import java.io.*;
import java.rmi.*;
public class slidsender
{
public static void main(String a[])throws Exception
{
ServerSocket ser=new ServerSocket(10);
Socket s=ser.accept();
DataInputStream in=new DataInputStream(System.in);
DataInputStream in1=new DataInputStream(s.getInputStream());
String sbuff[]=new String[8];
PrintStream p;
int sptr=0,sws=8,nf,ano,i;
String ch;
Do {
p=new PrintStream(s.getOutputStream());
System.out.print("Enter the no. of frames : ");
nf=Integer.parseInt(in.readLine());
p.println(nf);
if(nf<=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
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"));
}
}
How to Run Program
//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 evryone
Acknowledgment sent