-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cc
More file actions
33 lines (31 loc) · 715 Bytes
/
client.cc
File metadata and controls
33 lines (31 loc) · 715 Bytes
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
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int sockfd = socket(PF_INET, SOCK_STREAM, 0);
if(sockfd < 0)
{
fprintf(stderr, "Can't open socket.\n");
exit(1);
}
struct sockaddr_in servaddr;
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(10000);
inet_pton(AF_INET, "127.0.0.1", &(servaddr.sin_addr));
bool isConnceted = connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr));
if(isConnceted != -1)
{
fprintf(stderr, "Connected to local host.\n");
while(true);
}
else
{
fprintf(stderr, "Connection fails.\n");
exit(1);
}
}