Monday, 14 August 2017

(receiver side) Java Program to implementing Sliding Window Protocol while sending a message travelling from sender to receiver (CN)

/*Aim: A Java Program implementing Sliding Window Protocol while sending a message travelling from sender to receiver. */
/*For complete explanation visit: Prof. Brinda's Blog */
import java.io.DataInputStream; import java.io.PrintStream; import java.net.Socket; class slidreceiver { public static void main(String a[])throws Exception { Socket s=new Socket("localhost",7870); 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: //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

No comments:

Post a Comment