![]() |
|
|
| Subject:
stop-and-wait protocol in c language
Category: Computers Asked by: objkiran-ga List Price: $5.00 |
Posted:
18 Nov 2004 13:18 PST
Expires: 18 Dec 2004 13:18 PST Question ID: 430769 |
can anyone provide me with stop-and-wait protocol working code in c or c++ language |
|
| There is no answer at this time. |
|
| Subject:
Re: stop-and-wait protocol in c language
From: neo_bipin-ga on 19 Nov 2004 10:55 PST |
hi!
i have one c code that i have persnolly tried and it works it uses
com1 port to communicate
the code as below
/* 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");
}
}
if u have any doubts u can contact me at bipinramesh@gmail.com |
| Subject:
Re: stop-and-wait protocol in c language
From: abdmanaf-ga on 24 Nov 2004 23:49 PST |
You can use WaitForSingleObject() API call on windows for that purpose. Use INFINITE as the last parameter if you want to wait indefinitely. The function takes an object handle up on wich it waits. It could be a signal, mutex or could be its own handle. In this case, it would wait for ever. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |