-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.cpp
More file actions
36 lines (30 loc) · 861 Bytes
/
tests.cpp
File metadata and controls
36 lines (30 loc) · 861 Bytes
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 <iostream>
#include <string>
#include "src/TCPServer.h"
class RequestHander: public BaseRequestHandler {
public:
void handle() override {
char buf[1024];
while(conn.recv(buf, sizeof(buf)) > 0) {
std::cout << buf << std::endl;
if (buf[0] == 'e' && buf[1] == 'n' && buf[2] == 'd') break;
}
std::cout << "connection finished\n";
}
};
class RequestHandlerFactory: public BaseRequestHandlerFactory {
public:
RequestHander *createHandler() override {
return new RequestHander();
}
};
int main(int argc, char *argv[]) {
if (argc < 3) {
std::cerr << "usage:" << argv[0] << " host port\n";
return 1;
}
TCPServer s(argv[1], std::stoi(argv[2]), new RequestHandlerFactory);
std::cout << "server started\n";
s.serve_forever();
return 0;
}