-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
34 lines (28 loc) · 874 Bytes
/
Copy pathmain.cpp
File metadata and controls
34 lines (28 loc) · 874 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
#include <vector>
#include <memory>
#include "include/Server.hpp"
#include "include/Connection.hpp"
#include "include/HttpMessage/Request.hpp"
#include "include/HttpMessage/Response.hpp"
using namespace http;
int main(int argc, char *argv[])
{
try {
Server srv(65000, AF_INET);
std::vector< std::shared_ptr<Connection> > connections;
while (true)
{
connections.push_back(srv.Accept([](Connection& con){
std::string buffer;
con.readMessage(buffer);
std::cout << buffer << std::endl;
Request request(buffer);
Response response(request);
con.writeMessage(response.generateResponse());
con.closeSocket();
}));
}
} catch (const ServerException& se) { se.what(); }
// Never reached. Deconstructor is closing Server
return 0;
}