System.out.print('Acknowledgment received');
System.out.println(' for '+ano+'frames');
}
{
System.out.println('The no. of frames exceeds windowsize');
}
System.out.print('nDo you wants to send some moreframes : ');
}
s.close();
}
//RECEIVER PROGRAM
import java.net.*;
class slidreceiver
public static void main(String a[])throws Exception
Socket s=new Socket(InetAddress.getLocalHost(),10);
DataInputStreamin=new DataInputStream(s.getInputStream());
PrintStream p=new PrintStream(s.getOutputStream());
String rbuf[]=new String[8];
do
nf=Integer.parseInt(in.readLine());
{
{
rbuf[rptr]=in.readLine();
System.out.println('The received Frame '+rptr+' is : '+rbuf[rptr]);
rws-=nf;
p.println(rptr+1); rws+=nf; }
break;
}
}
Enter the no. of frames : 4
how r u
how is evryone
The received Frame 0 is : hiii
The received Frame 2 is : i am fine
importjava.net.*;
Socketsender;
ObjectInputStreamin;
intn,i=0,sequence=0;
public voidrun(){
BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in));
sender= new Socket('localhost',2004);
out=newObjectOutputStream(sender.getOutputStream());
in=newObjectInputStream(sender.getInputStream());
System.out.println('reciver > '+str);
packet=br.readLine();
do{
if(i
msg=msg.concat(packet.substring(i,i+1));
elseif(in){
}
sequence=(sequence0)?1:0;
System.out.println('datasent>'+msg);
System.out.println('waitingfor ack...nn');
i++;
System.out.println('receiver > '+' packet recievednn');
else{
System.out.println('Timeout resending data..nn');
}
}while(i
}catch(Exceptione){}
try{
out.close();
}
}
publicstatic void main(String args[]){
s.run();
}
//RECEIVER PROGRAM
import java.io.*;
public class Reciever{
Socketconnection=null;
ObjectInputStreamin;
inti=0,sequence=0;
public voidrun(){
BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in));
System.out.println('waitingfor connection..');
sequence=0;
out=newObjectOutputStream(connection.getOutputStream());
in=newObjectInputStream(connection.getInputStream());
do{
packet=(String)in.readObject();
if(Integer.valueOf(packet.substring(0,1))sequence){
sequence=(sequence0)?1:0;
}
{
System.out.println('nnreceiver >'+packet +' duplicate data');
if(i<3){
}
out.writeObject(String.valueOf((sequence+1)%2));
}
catch(Exceptione){}
System.out.println('Datarecived='+data);
}
finally{
in.close();
reciever.close();
catch(Exceptione){}
}
Recievers=new Reciever();
s.run();
Sliding Window Protocol Using Socket Programming Tools
}
}
OUTPUT:Waiting for Connection..
Enter the data to send..
data sent>0m
receiver > packet recieved
waiting for ack...
data sent>0n
receiver > packet recieved
waiting for ack...
data sent>1a
receiver > packet recieved
waiting for ack...
C++ Socket Programming Windows
data sent>1e
receiver > packet recieved
waiting for connection..
receiver >0m
receiver >0n
receiver >1a duplicate data
receiver >1e
waiting for connection..
Sliding Window Protocol Using Socket Programming Tool
Sliding Window Protocol | Set 1 (Sender Side) - GeeksforGeeks