-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.c
64 lines (51 loc) · 1.07 KB
/
client.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
char *ip;
int port;
int sockfd;
struct sockaddr_in server_address;
#include "common.h"
void sendMessage()
{
char buff[1024];
sprintf(buff, "test message.");
write(sockfd, buff, strlen(buff));
buff[0] = 0;
int r;
r = read(sockfd, buff, sizeof(buff));
buff[r] = 0;
if (r)
fprintf(stdout, "%s\n", buff);
}
void clientSetup()
{
if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
{
exit(EXIT_FAILURE);
}
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = inet_addr(ip);
server_address.sin_port = htons(port);
if (connect(sockfd, (struct sockaddr *) &server_address, sizeof(server_address)) < 0)
{
exit(EXIT_FAILURE);
}
sendMessage();
}
int main(int argc, char *argv[])
{
if (argc != 3)
{
printf("Usage %s <config_file_path> <root>.\n", argv[0]);
exit(1);
}
read_params(argv[1]);
clientSetup();
return 0;
}