selective repeat source code in c
#1

Below is the code for Go Back N ARQ. I need to implement the same code using selective repeat with different timer(real time) for each frame and a case where negative acknowledgement is sent by reciever.Please go through the code and post appropriate addition for Selective repeat ARQ
Code:
#include<iostream.h>

#include<conio.h>

#include<math.h>

class sender

{
      public :
int size,sf,sn,t,a[500],q[500],w,ff,sent  ;
sender(){}//default constructor
sender(int x,int aa)//parameterised constructor
{
ff=aa;//ff and aa = total no of frames
size=pow(2,x)-1;//size of sliding window
sn=0;//next frame to sent
sf=0;//first outstanding frame
w=0;//count of frames
if(aa<=5)
t=2;//timer (decremented by 1 after a frame is sent)
else
t=5;//timer (decremented by 1 after a frame is sent)
sent=0;
for(int i=0;i<aa;i=i+size+1)//to assign sequence no to frames
{
for(int j=0;j<=size;j++)
{
if(i+j < aa)
a[i+j]=j;
}
}
}
void reqstsend()//to send frames
{
if(w<ff)//check whether the no. of frame sent is less than total no of frames
{
if(t<=0 )//check for time out
{
cout<<endl<<"Caution : Timer out"<<endl;
timeout();
}
else if((sn-sf)>=size || sf==sn+1 )
{
cout<<endl<<"Caution : Window is full"<<endl;
t--;

}
  
/*else if(sn == size)//special case when sn==size sn should be =0
{
cout<<endl<<"frame F"<<sn<<" sent..."<<endl;
sn=0;
t--;
w++;
sent++;
show();
cout<<endl<<"frames sent :- ";
for(int i=0;i<w;i++)
{
        cout<<" "<<a[i]<<" ";
}
}*/
else//normal sending
{
cout<<endl<<"Frame F"<<sn<<" sent..."<<endl;
sn++;
t--;
w++;
sent++;
show();
cout<<endl<<"Frames sent :- ";
for(int i=0;i<w;i++)
{      
cout<<" "<<a[i]<<" ";
}
}
}
else
cout<<endl<<" ***All Frames Sent***"<<endl;
}
void arivack(int y)//recieving acknowledgement
{
sf=y;
t=sn-sf;
}
void timeout()
{
sn=sf;
if(ff<5)
{
  t=2;
w=w-2;
sent=sent-2;
}
Else
{    
t=5;
w=w-5;
sent=sent-5;
}
}
void sdisplay()//displaying frames initially
{
cout<<endl<<"Frames :- ";
for(int i=0;i<ff;i++)
cout<<" "<<a[i]<<" ";
cout<<endl<<endl<<"sn = "<<sn<<endl<<"sf = "<<sf<<endl;
}
void show()
{
     cout<<endl<<"No of frames sent ="<<sent<<endl;
}
};//class sender ends

class reciever : public sender
{
public :
int rn,b[500],c,reci;
sender *s;//sender class pointer
reciever(sender *y,int q)//contructor to initialise variables and element of array
{
reci =0;
rn=size;//next expected frame
c=0;//counter
for(int i=0;i<q;i++)
b[i]=0;
s=y;
}
void arivnot(int x)
{
if(rn == x)//recieve in order
{
if(rn != s->size)//recieving frames
{
b[c]=rn;
c++;
rn++;
}
else//special case when rn =size, then rn should be =0
{
b[c]=rn;
c++;
rn=0;
}
}
}
void sendack(int z)
{
cout<<endl<<"Acknowledgement A"<<z<<" sent"<<endl;
s->arivack(z);
}

void sendlostack(int z)
{
cout<<endl<<"Acknowledgement A"<<z<<" sent"<<endl;
}

void rdisplay()
{    
cout<<endl<<"No of frames recieved ="<<c<<endl;
cout<<endl<<"Frames recieved :- ";
for(int i=0;i<c;i++)
cout<<" "<<b[i]<<" ";
cout<<endl<<endl<<"rn = "<<rn<<endl<<endl;
}
};//class reciever ends  

int main()
{
int m,x=3,h,y,counter=0;
cout<<endl<<"Enter the value of sequence no. (m no of bits) => ";
cin>>m;
cout<<"Sliding window size ="<<pow(2,m-1)<<endl;
cout<<"Recieving window size ="<<pow(2,m-1)<<endl;
cout<<"Enter the total no of frames you want to send "<<endl;
cin>> h;
sender pqr(m,h),*g=&pqr;
reciever rec(g,h),*r=&rec;
while(1)
{
                 if(counter==0)
{
                      cout<<endl<<"Press 1 for going to sender side"<<endl
                      <<"Press 0 to exit"<<endl <<"enter code => ";
                     cin>>x;
if(x==2)
x=8;
counter++;
if(x!=1)
counter--;
}
else
{
             cout<<endl<<"Press 1 for going to sender side"<<endl <<"Press 2 for going to receiver             side"<<endl <<"Press 0 to exit"<<endl  <<"enter code => ";
cin>>x;
}
switch(x)
{
case 1 : while(y != 3)
{

            pqr.sdisplay();
            cout<<endl<<"Press 1 to send frame"<<endl <<"Press 2 to send frame (lost or incorrect)"<<endl
             <<"Press 3 to go back"<<endl<<" => ";
             cin>>y;
switch(y)

             {

             case 1 :
        
                  pqr.reqstsend();

                  if(pqr.sn == 0)

                  r->arivnot(pqr.size);

                  else

                  r->arivnot(pqr.sn-1);
    
                  break;

             case 2 : pqr.reqstsend();

                  break;

             case 3 :
                  
                   break;

             default :
                    
                   cout<<endl<<"Caution !!! error in code !!!  please enter right choice "<<endl;

                   break;

             }

             }

             y=0;

             break;

case 2 : while(y != 3)

             {

             r->rdisplay();

             cout<<endl<<"Press 1 to send Acknowledgement"<<endl

                        <<"Press 2 to send ack (lost)"<<endl
                        
                         <<"Press 3 to go back"<<endl

                         <<" => ";

             cin>>y;

             switch(y)

             {

             case 1 :
                  
                         r->sendack(rec.rn);  // cout<<endl<<"no of frames sent ="<<pqr.sent<<endl;

                         break;
              
             case 2:
                  
                         r->sendlostack(rec.rn);
                  
                   break;

             case 3:
                  
                   break;

             default :
                     cout<<endl<<"Caution !!! error in code !!!"<<endl;

                         break;

             }

             };

             y=0;

             break;

case 0 :
    
     exit(0);
    
      break;

default :
        
        cout<<endl<<"Caution !!! error in code !!!"<<endl;

                break;

}

}

getch();

return 0;

}
Reply
#2
When I search for selective repeat ARQ codes, this page is the first one to display which Is very misleading. so please stop sending this kind of bullshit request here n if possible send something which is actually of some use.
Reply
#3
(04-12-2012, 05:52 PM)Guest Wrote: Below is the code for Go Back N ARQ. I need to implement the same code using selective repeat with different timer(real time) for each frame and a case where negative acknowledgement is sent by reciever.Please go through the code and post appropriate addition for Selective repeat ARQ
Code:
#include<iostream.h>

#include<conio.h>

#include<math.h>

class sender

{
      public :
int size,sf,sn,t,a[500],q[500],w,ff,sent  ;
sender(){}//default constructor
sender(int x,int aa)//parameterised constructor
{
ff=aa;//ff and aa = total no of frames
size=pow(2,x)-1;//size of sliding window
sn=0;//next frame to sent
sf=0;//first outstanding frame
w=0;//count of frames
if(aa<=5)
t=2;//timer (decremented by 1 after a frame is sent)
else
t=5;//timer (decremented by 1 after a frame is sent)
sent=0;
for(int i=0;i<aa;i=i+size+1)//to assign sequence no to frames
{
for(int j=0;j<=size;j++)
{
if(i+j < aa)
a[i+j]=j;
}
}
}
void reqstsend()//to send frames
{
if(w<ff)//check whether the no. of frame sent is less than total no of frames
{
if(t<=0 )//check for time out
{
cout<<endl<<"Caution : Timer out"<<endl;
timeout();
}
else if((sn-sf)>=size || sf==sn+1 )
{
cout<<endl<<"Caution : Window is full"<<endl;
t--;

}
  
/*else if(sn == size)//special case when sn==size sn should be =0
{
cout<<endl<<"frame F"<<sn<<" sent..."<<endl;
sn=0;
t--;
w++;
sent++;
show();
cout<<endl<<"frames sent :- ";
for(int i=0;i<w;i++)
{
        cout<<" "<<a[i]<<" ";
}
}*/
else//normal sending
{
cout<<endl<<"Frame F"<<sn<<" sent..."<<endl;
sn++;
t--;
w++;
sent++;
show();
cout<<endl<<"Frames sent :- ";
for(int i=0;i<w;i++)
{      
cout<<" "<<a[i]<<" ";
}
}
}
else
cout<<endl<<" ***All Frames Sent***"<<endl;
}
void arivack(int y)//recieving acknowledgement
{
sf=y;
t=sn-sf;
}
void timeout()
{
sn=sf;
if(ff<5)
{
  t=2;
w=w-2;
sent=sent-2;
}
Else
{    
t=5;
w=w-5;
sent=sent-5;
}
}
void sdisplay()//displaying frames initially
{
cout<<endl<<"Frames :- ";
for(int i=0;i<ff;i++)
cout<<" "<<a[i]<<" ";
cout<<endl<<endl<<"sn = "<<sn<<endl<<"sf = "<<sf<<endl;
}
void show()
{
     cout<<endl<<"No of frames sent ="<<sent<<endl;
}
};//class sender ends

class reciever : public sender
{
public :
int rn,b[500],c,reci;
sender *s;//sender class pointer
reciever(sender *y,int q)//contructor to initialise variables and element of array
{
reci =0;
rn=size;//next expected frame
c=0;//counter
for(int i=0;i<q;i++)
b[i]=0;
s=y;
}
void arivnot(int x)
{
if(rn == x)//recieve in order
{
if(rn != s->size)//recieving frames
{
b[c]=rn;
c++;
rn++;
}
else//special case when rn =size, then rn should be =0
{
b[c]=rn;
c++;
rn=0;
}
}
}
void sendack(int z)
{
cout<<endl<<"Acknowledgement A"<<z<<" sent"<<endl;
s->arivack(z);
}

void sendlostack(int z)
{
cout<<endl<<"Acknowledgement A"<<z<<" sent"<<endl;
}

void rdisplay()
{    
cout<<endl<<"No of frames recieved ="<<c<<endl;
cout<<endl<<"Frames recieved :- ";
for(int i=0;i<c;i++)
cout<<" "<<b[i]<<" ";
cout<<endl<<endl<<"rn = "<<rn<<endl<<endl;
}
};//class reciever ends  

int main()
{
int m,x=3,h,y,counter=0;
cout<<endl<<"Enter the value of sequence no. (m no of bits) => ";
cin>>m;
cout<<"Sliding window size ="<<pow(2,m-1)<<endl;
cout<<"Recieving window size ="<<pow(2,m-1)<<endl;
cout<<"Enter the total no of frames you want to send "<<endl;
cin>> h;
sender pqr(m,h),*g=&pqr;
reciever rec(g,h),*r=&rec;
while(1)
{
                 if(counter==0)
{
                      cout<<endl<<"Press 1 for going to sender side"<<endl
                      <<"Press 0 to exit"<<endl <<"enter code => ";
                     cin>>x;
if(x==2)
x=8;
counter++;
if(x!=1)
counter--;
}
else
{
             cout<<endl<<"Press 1 for going to sender side"<<endl <<"Press 2 for going to receiver             side"<<endl <<"Press 0 to exit"<<endl  <<"enter code => ";
cin>>x;
}
switch(x)
{
case 1 : while(y != 3)
{

            pqr.sdisplay();
            cout<<endl<<"Press 1 to send frame"<<endl <<"Press 2 to send frame (lost or incorrect)"<<endl
             <<"Press 3 to go back"<<endl<<" => ";
             cin>>y;
switch(y)

             {

             case 1 :
        
                  pqr.reqstsend();

                  if(pqr.sn == 0)

                  r->arivnot(pqr.size);

                  else

                  r->arivnot(pqr.sn-1);
    
                  break;

             case 2 : pqr.reqstsend();

                  break;

             case 3 :
                  
                   break;

             default :
                    
                   cout<<endl<<"Caution !!! error in code !!!  please enter right choice "<<endl;

                   break;

             }

             }

             y=0;

             break;

case 2 : while(y != 3)

             {

             r->rdisplay();

             cout<<endl<<"Press 1 to send Acknowledgement"<<endl

                        <<"Press 2 to send ack (lost)"<<endl
                        
                         <<"Press 3 to go back"<<endl

                         <<" => ";

             cin>>y;

             switch(y)

             {

             case 1 :
                  
                         r->sendack(rec.rn);  // cout<<endl<<"no of frames sent ="<<pqr.sent<<endl;

                         break;
              
             case 2:
                  
                         r->sendlostack(rec.rn);
                  
                   break;

             case 3:
                  
                   break;

             default :
                     cout<<endl<<"Caution !!! error in code !!!"<<endl;

                         break;

             }

             };

             y=0;

             break;

case 0 :
    
     exit(0);
    
      break;

default :
        
        cout<<endl<<"Caution !!! error in code !!!"<<endl;

                break;

}

}

getch();

return 0;

}

Reply
#4
please post the c code for client server selective repeat
Reply
#5
Description: This project deals with the Demonstration of the 'Selective Repeat ARQ'. All the things from successful sending to packet loss as well as the Ack sending and the loss is well demonstrated. There is also timer show to make the project look more realistic. The project is wholly represented the flow of packets in a network and the various aspect that challenges to it.

USAGES: Welcome screen open and which remain for few seconds and the second page where you will find different menu to view the different demos. Select the Menu and see what you want to view.



SEND WINDOW : View the sender window
RECEIVE WINDOW: View the receiver window
SAFE SENDING : Demo the sending of packet from source to destination
PACKET CRASHING : The loss and crashing of packet is demoed.
TIME OUT: Packet those which didn't reach at the proper time.
EXIT : Close the program.

After each demo you are asked to go to menu for selection, demo it again press N to no and Y for yes.

Project Code: Download :http://openglprojects2011/10/selective-repeat-arq.html#gsc.tab=0


Note: Change the speed of flow of packet as per you need as well change the pixels or the coordinate according to the screen.
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Tagged Pages: sourse code for selective repeat arq, sliding window protocol selective repeat c program, implementing selective repeat protocol code in sliding window, program of selective repaet protocol, sender receiver program of selective repeat protocol in c, c code for dselective repeat sliding window protocol, program on selective arq,
Popular Searches: pournami lottery repeat number, selective repeat arq protocol program in c, selective image source code in java, selective repeat sliding window protocol program in c, implementing selective repeat protocol code, c program for selective repeat protocol, selective arq source code,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  free download source code of online college magazine 5 17,723 29-06-2018, 10:09 AM
Last Post: Guest
  opengl source code for butterfly 3 3,253 14-05-2018, 08:57 AM
Last Post: Akshatha k
  ice cream parlour management system in vb source code 4 5,282 04-04-2018, 11:58 PM
Last Post: vprk77
  source code in php for online training and placement cell management 1 6,676 23-03-2018, 09:06 AM
Last Post: ritzi
  free download college website project in html with source code 2 4,617 24-02-2018, 10:46 AM
Last Post: Guest
  source code for hospital management system in jsp 4 1,947 13-01-2018, 10:51 AM
Last Post: dhanabhagya
  source code in c for dna cryptography in computer sc ppt 1 1,522 09-01-2018, 09:59 PM
Last Post: harshavarshinib
  java programmings for bus ticket reservation source code 1 6,212 09-11-2017, 11:28 PM
Last Post: Ayushi Nagar
  location alarm android tutorial and source code 1 1,444 14-10-2017, 02:53 PM
Last Post: shakil19944
  source code in matlab for fuzzy based traffic light controll system 2 1,319 08-10-2017, 02:12 PM
Last Post: nomanamjad143

Forum Jump: