-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientSL.c
69 lines (59 loc) · 1.59 KB
/
clientSL.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h> //for close()
int main(int argc, char *argv[])
{
int client_socket;
struct sockaddr_in server_address;
int window_size;
int frame=0;
int ACK;
int val;
int i, count;
char sentdata[50];
char recvdata[50];
client_socket = socket(AF_INET, SOCK_STREAM, 0);
server_address.sin_family = AF_INET;
server_address.sin_port = htons(8080);
server_address.sin_addr.s_addr = inet_addr("127.0.0.1");
//connect() instead of recv()
connect(client_socket, (struct sockaddr *) &server_address, sizeof(server_address));
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;
}
while(1)
{
printf("\n\nEnter Frame Number : ");
scanf("%d", &val);
send(client_socket, &val,sizeof(val),0);
printf("Enter data: ");
scanf("%s", sentdata);
send(client_socket,sentdata,strlen(sentdata),0);
if(strcmp(sentdata,"end")==0)
break;
recv(client_socket, &count,sizeof(count),0);
i=recv(client_socket,recvdata,50,0);
recvdata[i]='\0';
printf("\n %s %d", recvdata,count);
}
close(client_socket);
return 0;
}