-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.cpp
77 lines (70 loc) · 2.36 KB
/
client.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
#include <arpa/inet.h>
#include <fcntl.h>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <sys/socket.h>
#include <unistd.h>
#include <vector>
int main() {
int port = 55000;
std::string ip = "127.0.0.1";
int sock = 0;
if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
exit(1);
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(ip.c_str());
addr.sin_port = htons(port);
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
exit(1);
sleep(1);
std::string req = "GET / HTTP/1.1\r\n"
"User-Agent: curl/7.68.0\r\n"
"Host: 0.0.0.0:999\r\n"
"Accept: */*\r\n"
"\r\n"
"GET / HTTP/1.1\r\n"
"User-Agent: curl/7.68.0\r\n"
"Host: 0.0.0.0:999\r\n"
"Accept: */*\r\n"
"\r\n"
"GET / HTTP/1.1\r\n"
"User-Agent: curl/7.68.0\r\n"
"Host: 0.0.0.0:999\r\n"
"Accept: */*\r\n"
"\r\n"
"GET / HTTP/1.1\r\n"
"User-Agent: curl/7.68.0\r\n"
"Host: 0.0.0.0:999\r\n"
"Accept: */*\r\n"
"\r\n"
"GET / HTTP/1.1\r\n"
"User-Agent: curl/7.68.0\r\n"
"Host: 0.0.0.0:999\r\n"
"Accept: */*\r\n"
"\r\n"
"GET / HTTP/1.1\r\n"
"User-Agent: curl/7.68.0\r\n"
"Host: 0.0.0.0:999\r\n"
"Accept: */*\r\n"
"\r\n"
"GET / HTTP/1.1\r\n"
"User-Agent: curl/7.68.0\r\n"
"Host: 0.0.0.0:999\r\n"
"Connection: Close\r\n"
"Accept: */*\r\n\r\n";
write(sock, req.c_str(), req.size());
// int send_count = 100;
// std::cout << "send_count: " << send_count << std::endl;
// std::vector<char> str(50000, 'A');
// write(sock, &str[0], send_count);
// sleep(1);
// char buf[5000];
// int rc = read(sock, &buf, 5000);
// buf[rc] = '\0';
// std::cout << "rc: " << rc << std::endl;
// std::cout << buf << std::endl;
close(sock);
return 0;
}