-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClientGoBackN.c
54 lines (49 loc) · 1.51 KB
/
ClientGoBackN.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
45
46
47
48
49
50
51
52
53
54
//CLIENT-------------------------------------------------------------------------------
//This code is contributed by Anas Jawed
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
int main(){
int sock,cport,val,count,i;
int window_size;
int frame=0;
int ACK,client_socket;
char sentdata[50],recvdata[50];
struct sockaddr_in servaddr;
printf("Enter the port");
printf("\n");
scanf("%d",&cport);
printf("%d\n",cport);
sock=socket(AF_INET,SOCK_STREAM,0);
if(sock<0)
printf("Can't create\n");
else
printf("Socket is created\n");
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(cport);
if(connect(sock,(struct sockaddr*)&servaddr,sizeof(servaddr))<0)
printf("Can't connect\n");
else
printf("Connected\n");
printf("Enter the Window Size\n");
scanf("%d",&window_size);
send(client_socket,&window_size,sizeof(window_size),0);
while(frame<window_size){
for(i=0;i<window_size;i++){
printf("Transmitted Frames to the server %d\n",frame);
send(client_socket,&frame,sizeof(frame),0);
frame++;
if(frame==window_size)
break;
}
recv(client_socket,&ACK,sizeof(ACK),0);
printf("The negative Acknowledgement received from the server is %d\n",ACK);
if(ACK==window_size)
break;
else
frame=ACK;
}
return 0;
}