0% found this document useful (0 votes)
29 views

Ex 1A Sliding Window

This document describes the implementation of a sliding window protocol for data transmission between a sender and receiver. The sender accepts input frames from the user, sends them to the receiver over a socket connection, and waits for acknowledgments. The receiver receives frames over the socket, prints them out, and sends acknowledgments back to the sender. The program uses a sliding window of size 8 to control the number of unacknowledged frames that can be sent at once.

Uploaded by

Mohammed Fazil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Ex 1A Sliding Window

This document describes the implementation of a sliding window protocol for data transmission between a sender and receiver. The sender accepts input frames from the user, sends them to the receiver over a socket connection, and waits for acknowledgments. The receiver receives frames over the socket, prints them out, and sends acknowledgments back to the sender. The program uses a sliding window of size 8 to control the number of unacknowledged frames that can be sent at once.

Uploaded by

Mohammed Fazil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

IMPLEMENTATION OF SLIDING WINDOW PROTOCOL

SENDER:

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"));
}
}

OUTPUT

SENDER:
Z:\>java slidsender
Enter the no. of frames : 4
Enter 4 Messages to be send

10000
11000
11100
11110
Acknowledgment received for 4 frames

Do you wants to send some more frames : no

RECEIVER:

Z:\>java slidreceiver

The received Frame 0 is : 10000


The received Frame 1 is : 11000
The received Frame 2 is : 11100
The received Frame 3 is : 11110

Acknowledgment sent

You might also like