-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_server.cc
36 lines (27 loc) · 981 Bytes
/
main_server.cc
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
#include "tcpclient.h"
#include "tcpserver.h"
#include <cstdio>
int main() {
TcpServer server{ 90000, 60 };
printf("error: %ld\n", server.error);
printf("socket: %08x\n", server.handle);
printf("message: %s\n", es_error_message(server.error).c_str());
auto client = server.accept_client(true);
printf("client: %ld\n", client);
printf("error: %ld\n", server.error);
if (client == nullptr)
return 1;
auto resp = client->recv_string('\n');
printf("resp: %ld %s\n", resp.length(), resp.c_str());
printf("error: %ld\n", client->error);
auto res = client->write_string("HTTP/1.1 200 OK\r\n");
printf("res: %ld\n", res);
printf("error: %ld\n", client->error);
res = client->write_string("Server: EvilSocket/1.0\r\n");
printf("res: %ld\n", res);
printf("error: %ld\n", client->error);
getchar();
res = client->write_string("Date: Undefined point in space-time continuum\r\n");
printf("res: %ld\n", res);
printf("error: %ld\n", client->error);
}