forked from esnce/tinyhttpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleclient.c
43 lines (33 loc) · 828 Bytes
/
simpleclient.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int sockfd;
socklen_t len;
struct sockaddr_in address;
int result;
char buff[1024]="GET /index.html HTTP/1.0\r\n\r\n";
sockfd = socket(AF_INET, SOCK_STREAM, 0);
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr("127.0.0.1");
address.sin_port = htons(9999);
len = sizeof(address);
result = connect(sockfd, (struct sockaddr *)&address, len);
if (result == -1)
{
perror("oops: client1");
exit(1);
}
write(sockfd, buff, strlen(buff));
memset(buff,0x00,sizeof buff);
read(sockfd, buff, sizeof(buff)-1);
printf("char from server = \n%s\n", buff);
close(sockfd);
return (0);
}