Name: Abhinav Karney Rollno: 32 Problem Statement
Name: Abhinav Karney Rollno: 32 Problem Statement
Name: Abhinav Karney Rollno: 32 Problem Statement
Rollno : 32
Problem Statement:
Write a program to simulate Go back N and Selective Repeat Modes of Sliding Window
Protocol in peer to peer mode and demonstrate the packets captured traces using Wireshark
Packet Analyzer Tool for peer to peer mode.
Go Back N-
int pc=in.read();
System.out.println("Sending....");
if(pc==0)
{
for(int i=0;i<p;++i)
{
System.out.println("sending frame number "+i);
out.write(i);
out.flush();
System.out.println("Waiting for acknowledgement");
try
{
Thread.sleep(7000);
}
catch(Exception e){}
int a=in.read();
System.out.println("received acknowledgement for frame "+i+" as "+a);
}
out.flush();
}
else
{
for(int i=0;i<p;++i)
{
if(i==2)
{
System.out.println("sending frame no "+i);
}
else
{
System.out.println("sending frame no "+i);
out.write(i);
out.flush();
System.out.println("Waiting for acknowledgement ");
try
{
Thread.sleep(7000);
}
catch(Exception e){}
int a=in.read();
if(a!=255)
{
System.out.println("received ack for frame no: "+i+" as "+a);
f[i]=true;
}
}// end of inner else
}// end of for
for(int a=0;a<p;++a)
{
if(f[a]==false)
{
System.out.println("Resending frame "+a);
out.write(a);
out.flush();
System.out.println("Waiting for ack ");
try
{
Thread.sleep(5000);
}
catch(Exception e){}
int b=in.read();
System.out.println("received ack for frame no: "+a+" as "+b);
f[a]=true;
}
}
out.flush();
}// end of else which is for error
in.close();
out.close();
client.close();
ss.close();
System.out.println("Quiting");
class TestCli
{
System.out.println(".......Client........");
System.out.println("Connect");
System.out.println("Enter the number of frames to be requested to the server");
int c=scr.nextInt();
out.write(c);
out.flush();
int check=0;
int i=0;
int j=0;
if(choice==0)
{
for(j=0;j<c;++j)
{
i=in.read();
System.out.println("received frame no: "+i);
System.out.println("Sending acknowledgement for frame no: "+i);
out.write(i);
out.flush();
}
out.flush();
}
else
{
for(j=0;j<c;++j)
{
i=in.read();
if(i==check)
{
System.out.println("received frame no: "+i);
System.out.println("Sending acknowledgement for frame no: "+i);
out.write(i);
++check;
}
else
{
--j;
System.out.println("Discarded frame no: "+i);
System.out.println("Sending NEGATIVE ack");
out.write(-1);
}
out.flush();
}
}//end of else for error
in.close();
out.close();
System.out.println("Quiting");
D:\CN>java TestSer
...........Server..........
Waiting for connection....
Received request for sending frames
Sending....
sending frame no 0
Waiting for acknowledgement
received ack for frame no: 0 as 0
sending frame no 1
Waiting for acknowledgement
received ack for frame no: 1 as 1
sending frame no 2
sending frame no 3
Waiting for acknowledgement
sending frame no 4
Waiting for acknowledgement
sending frame no 5
Waiting for acknowledgement
sending frame no 6
Waiting for acknowledgement
Resending frame 2
Waiting for ack
received ack for frame no: 2 as 2
Resending frame 3
Waiting for ack
received ack for frame no: 3 as 3
Resending frame 4
Waiting for ack
received ack for frame no: 4 as 4
Resending frame 5
Waiting for ack
received ack for frame no: 5 as 5
Resending frame 6
Waiting for ack
received ack for frame no: 6 as 6
Quiting
D:\CN>
D:\CN>javac TestCli.java
D:\CN>java TestCli
Localhost/127.0.0.1
.......Client........
Connect
Enter the number of frames to be requested to the server
7
Enter the type of trans. Error=1 ; No Error=0
1
received frame no: 0
Sending acknowledgement for frame no: 0
received frame no: 1
Sending acknowledgement for frame no: 1
Discarded frame no: 3
Sending NEGATIVE ack
Discarded frame no: 4
Sending NEGATIVE ack
Discarded frame no: 5
Sending NEGATIVE ack
Discarded frame no: 6
Sending NEGATIVE ack
received frame no: 2
Sending acknowledgement for frame no: 2
received frame no: 3
Sending acknowledgement for frame no: 3
received frame no: 4
Sending acknowledgement for frame no: 4
received frame no: 5
Sending acknowledgement for frame no: 5
received frame no: 6
Sending acknowledgement for frame no: 6
Quiting
D:\CN>
Selective Repeat ARQ
int k = dis.read();
dos.write(a[k]);
dos.flush();
} catch (IOException e)
{
System.out.println(e);
}finally
{
try {
dis.close();
dos.close();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}//main end
}//class end
******************************************************************************
Client Side Code:
//package selR;
}//main end
}//class end
******************************************************************************
Server Side Output:
D:\CN>javac Ser.java
D:\CN>java Ser
Enter no. of frames to transmit:6
Enter the data elements carried in frames:
5
12
43
6
3
1
waiting for connection
The number of packets sent is:6
D:\CN>
******************************************************************************
Client Side Output:
D:\CN>javac Cli.java
D:\CN>java Cli
Localhost/127.0.0.1
No of frame is:6
5
12
43
6
3
1
Enter sequence of frame no which is in error4
Received frame is: 5
Received frame is: 12
Received frame is: 43
Received frame is: 6
Received frame is: -1
Received frame is: 1
Request to retransmit frame no 5 again!!
D:\CN>