-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
31 lines (23 loc) · 867 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
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char *argv[]){
char *address;
address = argv[1];
int client_socket = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in remote_address;
remote_address.sin_family = AF_INET;
remote_address.sin_port = htons(9001);
inet_aton(address, (struct in_addr*)&remote_address.sin_addr.s_addr);
connect(client_socket, (struct sockaddr*)&remote_address, sizeof(remote_address));
char request[] = "GET / HTTP/1.1\r\n\r\n";
char response[4096];
send(client_socket, request, sizeof(request), 0);
recv(client_socket, response, sizeof(response), 0);
printf("Response from server:\n%s", response);
close(client_socket);
}