answersLogoWhite

0


Best Answer

/*************************************************************************************/

/* C program to implement stop and wait protocol*/

/* Download more programs at http://sourcecode4u.com/ */

/*************************************************************************************/

#include<stdio.h>

#include<conio.h>

#define MAXSIZE 100

typedef struct

{

unsigned char data[MAXSIZE];

}packet;

typedef enum{data,ack}frame_kind;

typedef struct

{

frame_kind kind;

int sq_no;

int ack;

packet info;

}frame;

typedef enum{frame_arrival}event_type;

typedef enum{true_false}boolean;

void frame_network_layer(packet *p)

{

printf("\n from network arrival");

}

void to_physical_layer(frame *f)

{

printf("\n to physical layer");

}

void wait_for_event(event_type *e)

{

printf("\n waiting for event n");

}

void sender(void)

{

frame s;

packet buffer;

event_type event;

printf("\n ***SENDER***");

frame_network_layer(&buffer);

s.info=buffer;

to_physical_layer(&s);

wait_for_event(&event);

}

void from_physical_layer(frame *f)

{

printf("from physical layer");

}

void to_network_layer(packet *p)

{

printf("\n to network layer");

}

void receiver(void)

{

frame r,s;

event_type event;

printf("\n ***RECEIVER***");

wait_for_event(&event);

from_physical_layer(&r);

to_network_layer(&r.info);

to_physical_layer(&s);

}

main()

{

sender();

receiver();

getch();

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

/* Stop and Wait Protocol ( Flow Control ) */

#include<stdio.h>

#include<bios.h>

#include<conio.h>

#define COM1 0

#define SETTINGS 0x82

#define DTR 0x100

void main()

{

int ch,status,i=0,true=1;

char msg[100],ack,rec;

clrscr();

bioscom(0,SETTINGS,COM1);

printf("\n 1.Transmit\n 2.Receive");

printf("\n\n Enter the operation code : ");

scanf("%d",&ch);

switch(ch)

{

case 1 : printf("\n Enter the Message \n ");

scanf("%s",&msg);

while(msg[i]!='\0')

{

bioscom(1,msg[i],COM1);

printf("\n%c",msg[i]);

do

{

while(1)

{

status=bioscom(3,0,COM1);

if(status & DTR)

{

ack=bioscom(2,0,COM1) & 0x7F;

if(ack=='0')

{

bioscom(1,msg[i],COM1);

printf("\n%c - retransmitted ",msg[i]);

}

break;

}

}

}while(ack!='1');

i++;

}

break;

case 2 : printf("\n Receiver \t Press Escape to quit\n\n");

do

{

status=bioscom(3,0,COM1);

if(status & DTR)

{

rec=bioscom(2,0,COM1);

printf("\n%c -- Enter ACK(1 for +ve, 0 for -ve) :",rec);

ack=getche();

bioscom(1,ack,COM1);

}

if(kbhit())

if(getch()=='\x1b')

true=0;

}while(true);

break;

default : printf("\n Invalid Selection");

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Program for stop and wait protocol in c language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program for stop and wait protocol in implementing reliable transport protocol?

Take a look at any definition for TCP protocol. Most are also written in C.


What is stop and wait protocol?

Stop and wait protocol is used in telecommunications as a method to send information between two connected devices. It sends information in a Protocol Data Unit and waits for a response.


Do stop and wait protocol has negative acknowledgements?

No. They don't have NAKs


Which protocol comes under noiseless channel?

stop and wait, go-back-n


Stop n wait protocol is associated with which layer?

Data link layer of the OSI model..


How do you stop windows vista from automatically closing programs and wait for them to respond?

The only time Windows Vista automatically closes programs is when it is performing a system restart after an update. You can stop this from happening by turning off automatic updates. Sometimes, a program may stop responding and you can choose to wait for the issue to rectify itself or close the program down manually.


What is the advantage of sliding window protocol over stop and wait protocol?

On data links with long transmission delays (e.g. communication satellites) sliding windows protocol allows multiple packets to be in transit pending ACK packets back from the receiver (up to the limit of the window size), which allows for nearly continuous transmission of packets through the data link. On data links with long transmission delays (e.g. communication satellites) stop and wait protocol forces the transmitter to wait until it receives an ACK packet on every packet sent. If the transmission delays are long enough, the data link may be quiet and completely idle for the great majority of the time which is a serious waste of the resource.


Where can you find a model for stop and wait protocol?

http://www.erg.abdn.ac.uk/users/gorry/course/arq-pages/saw.html This was the first site google found. Try googling some more..


What is the hink-pink for blue green moray?

TEAL EEL


How do you say wait in abaluya language?

The English word 'wait', is said in African Abaluhya (Luhya) language as "lindaa".


A system uses the Stop-and-Wait ARQ protocol If each packet carries 1000 bits of data how long does it take to send 1 million bits of data if the distance between the sender and receiver is 5000 Km?

5555


To stop a board from chipping on the end as you plane you can?

wait..........wait what?