Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

client side for go back N protocol in computer networks #467

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions scripts/GobackClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import java.util.*;
import java.net.*;
import java.io.*;
public class GobackClient {

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Socket s=new Socket("localhost",4001);
DataInputStream in=new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
Scanner sc=new Scanner(System.in);
int frame_size=10,m,res,val=0;
double wind;
m=in.readInt();
wind=(Math.pow(2,m))-1;
int []a=new int[frame_size];
for(int i=0;i<a.length;i++)
{
if((i-val)%wind==0 && i>0)
{
System.out.println("Enter 1 if you've received all the frames:\n");
res=sc.nextInt();
out.writeInt(res);
if(res!=1)
{
int j;
System.out.println("Enter the frame that you didn't receive:\n");
res=sc.nextInt();
out.writeInt(res);
//System.out.println("lets retransmit it:\n");
for(j=res-1;j<res-1+wind;j++)
{
a[j]=in.readInt();
System.out.println("received frame" + (j+1) + "is" + a[j]);
}
i=j;
val=(res-1)/(int)wind;
continue;
}
else
{
int j;
System.out.println("Acknowledgement has been sent for" + i);
int res1=in.readInt();
if(res1==1)
System.out.println("acknowledgement received\n");
else
{
System.out.println("Acknowledgement not received\n");
for(j=i-(int)wind;j<i;j++)
{
a[j]=in.readInt();
System.out.println("received frame(1)" + (j+1) + "is" + a[j]);
}
i=j;
continue;
}
}
}
if(i==a.length)
break;
a[i]=in.readInt();
System.out.println("received frame from server" + i);
}
in.close();
out.close();
sc.close();
s.close();
}

}
65 changes: 65 additions & 0 deletions scripts/GobackServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import java.util.*;
import java.net.*;
import java.io.*;
public class GobackServer {
public static void main(String args[]) throws IOException
{
ServerSocket ss=new ServerSocket(4001);
Socket s=ss.accept();
DataInputStream in=new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
Scanner sc=new Scanner(System.in);
int frame_size=10,m,res,val=0;
double wind;
int []a=new int[frame_size];
for(int i=0;i<frame_size;i++)
{
System.out.println("Frame no. is: "+ (i+1));
a[i]=sc.nextInt();
}
System.out.println("Enter the value of m:\n");
m=sc.nextInt();
wind=(Math.pow(2,m))-1;
out.writeInt(m);
for(int i=0;i<a.length;i++)
{
if((i-val)%wind==0 && i>0)
{
res=in.readInt();
if(res!=1)
{
int j;
res=in.readInt();
System.out.println("lets retransmit it:\n");
for(j=res-1;j<res-1+wind;j++)
out.writeInt(a[j]);
i=j;
val=(res-1)/(int)wind;
continue;
}
else
{
System.out.println("Enter 1 if You've received the acknowledgement for the frame"+ i + ":\n ");
res=sc.nextInt();
out.writeInt(res);
if(res!=1)
{
int j;
for(j=res-1;j<res-1+wind;j++)
out.writeInt(a[j]);
i=j;
continue;
}
}
}
if(i==a.length)
break;
out.writeInt(a[i]);
}
in.close();
out.close();
sc.close();
s.close();
ss.close();
}
}