forked from 8BitSec/CN_practicals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cn_4.c
44 lines (36 loc) · 843 Bytes
/
cn_4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int nf,N;
int no_tr=0;
srand(time(NULL));
printf("Enter no. of frames: "); scanf("%d",&nf);
printf("\nEnter the Window size: "); scanf("%d",&N);
printf("\n\n");
int i=1, j;
while(i<=nf)
{
int x=0;
for(j=i;j<i+N && j<=nf;j++,no_tr++) printf("Sent frame %d ",j);
for(j=i;j<i+N && j<=nf;j++)
{
int flag = rand() % 2;
if(!flag)
{
printf("Acknowledgment for Frame %d\n",j);
x++;
}
else
{ printf("Frame %d NOT Received\n", j);
printf("Retransmitting Window\n");
break;
}
}
printf("\n");
i += x;
}//while
printf("Total number of transmissions : %d\n",no_tr);
return 0;
}