-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
38 lines (32 loc) · 838 Bytes
/
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
#include "handler/client_handler.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <stdlib.h>
int main()
{
int sockfd;
struct sockaddr_in serverAddress;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
printf("Error in creating socket\n");
exit(1);
}
serverAddress.sin_addr.s_addr = inet_addr("127.0.0.1");
serverAddress.sin_family = AF_INET;
serverAddress.sin_port = htons(PORT_NO);
int status = connect(sockfd, (struct sockaddr *)&serverAddress, sizeof(serverAddress));
if (status < 0)
{
printf("Error in connecting\n");
exit(1);
}
printf("Connected to server\n");
handleServerConnection(sockfd);
return 0;
}