-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGameServer.cpp
More file actions
52 lines (40 loc) · 1.27 KB
/
GameServer.cpp
File metadata and controls
52 lines (40 loc) · 1.27 KB
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
#include <iostream>
#include <sys/sysinfo.h>
#include "http_server.h"
#include "io_service_pool.h"
int main(int argc, char* argv[])
{
try
{
http_server s(tcp::v4(), 8080, get_nprocs() * 2, [](request &request_, response &response_){
Json::Reader reader;
Json::Value root;
if (!reader.parse(request_.get_body(), root, false))
{
return -1;
}
try
{
std::string ClientVersion = root["ClientVersion"].asString();
std::string SceneId = root["SceneId"].asString();
int Value = root["Value"].asInt();
/*std::cout << ClientVersion << std::endl;
std::cout << SceneId << std::endl;
std::cout << Value << std::endl;*/
}
catch (const std::exception &e)
{
std::cout << e.what() << std::endl;
}
response_.getValue()["name"] = "My name is haha.";
response_.getValue()["age"] = "30";
});
std::cout << "Server running at http://0.0.0.0:8080/" << std::endl;
s.run();
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}