-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.c
65 lines (55 loc) · 1.4 KB
/
test2.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
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
int client_len;
int client_sockfd;
FILE *fp_in;
char buf_in[255];
char buf_get[255];
struct sockaddr_in clientaddr;
if (argc != 2)
{
printf("Usage : ./zipcode_cl [port]\n");
printf("예 : ./zipcode_cl 4444\n");
exit(0);
}
client_sockfd = socket(AF_INET, SOCK_STREAM, 0);
clientaddr.sin_family = AF_INET;
clientaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
clientaddr.sin_port = htons(atoi(argv[1]));
client_len = sizeof(clientaddr);
if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) < 0)
{
perror("Connect error: ");
exit(0);
}
while(1)
{
printf("지역이름 입력 : ");
fgets(buf_in, 255,stdin);
buf_in[strlen(buf_in) - 1] = 0;
write(client_sockfd, buf_in, 255);
if (strncmp(buf_in, "quit", 4) == 0)
{
close(client_sockfd);
exit(0);
}
while(1)
{
read(client_sockfd, buf_get, 255);
printf("%s", buf_get);
if (strncmp(buf_get, "end", 3) == 0)
break;
}
}
close(client_sockfd);
exit(0);
}