-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
58 lines (48 loc) · 1.2 KB
/
Copy pathclient.c
File metadata and controls
58 lines (48 loc) · 1.2 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <string.h>
#define port 12348
#define buff_size 256
int main()
{
int frame[2];
frame[0] = 1;
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
{
perror("socket");
exit(1);
}
int opt = 1;
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
struct sockaddr_in client_address;
client_address.sin_family = AF_INET;
client_address.sin_port = htons(port);
client_address.sin_addr.s_addr = INADDR_ANY;
int conncheck = connect(sockfd, (struct sockaddr*) &client_address, sizeof(client_address));
if (conncheck == -1)
{
perror("Connect");
exit(1);
}
printf("Enter the number of frames to send: ");
scanf("%d", &frame[1]);
while(frame[1]>0)
{
// frame[0] = 0
frame[0] = (frame[0] + 1)%2;
int sendcheck = send(sockfd,frame, sizeof(frame), 0);
printf("\nFrame[%d] sent\n", frame[0]);
if (sendcheck == -1)
{
perror("send");
exit(1);
}
recv(sockfd, frame, sizeof(frame), 0);
printf("\nAcknowledgment for Frame[%d] recived\n", frame[0]);
}
close(sockfd);
return 0;
}