-
Notifications
You must be signed in to change notification settings - Fork 0
/
websocket.cpp
97 lines (87 loc) · 2.77 KB
/
websocket.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "serverResource.hpp"
#include "serverResources.hpp"
int main() {
try
{
unsigned short port,ports;
size_t threads;
string upload_url;
string rename_url;
string delete_url;
string list_url;
string server_crt;
string server_key;
{
string fullpath = boost::filesystem::initial_path<boost::filesystem::path>().string();
boost::property_tree::ptree pt;
boost::property_tree::ini_parser::read_ini(fullpath+"/config.ini", pt);
cout << fullpath << endl;
port = boost::lexical_cast<unsigned short>(pt.get<std::string>("webserver.port"));
ports = boost::lexical_cast<unsigned short>(pt.get<std::string>("webserver.ports"));
threads = boost::lexical_cast<size_t>(pt.get<std::string>("webserver.threads"));
server_crt=pt.get<std::string>("webserver.server_crt");
server_key=pt.get<std::string>("webserver.server_key");
upload_url = "^/" + pt.get<std::string>("webserver.upload_url") + "/?$";
rename_url = "^/" + pt.get<std::string>("webserver.rename_url") + "/?$";
delete_url = "^/" + pt.get<std::string>("webserver.delete_url") + "/?$";
list_url = "^/" + pt.get<std::string>("webserver.list_url") + "/?$";
nfspath = pt.get<std::string>("nfs.path");
}
cout << port << endl;;
cout << threads << endl;;
cout << upload_url << endl;;
cout << rename_url << endl;;
cout << delete_url << endl;;
cout << list_url << endl;;
cout << nfspath << endl;;
if (!boost::filesystem::exists(nfspath))
{
cout << "\nNot found: " << nfspath << endl;
if (create_dir(nfspath))
{
cout << "create path: " << nfspath << endl;
}
else
{
cout << "create path failed: " << nfspath << endl;
}
}
//WebSocket (WS)-server at port 8080 using 4 threads
WsServer server(port, threads);
serverResourceUpload(server, upload_url);
serverResourceRename(server, rename_url);
serverResourceDelete(server, delete_url);
serverResourceList(server, list_url);
thread server_thread([&server](){
//Start WS-server
server.start();
});
this_thread::sleep_for(chrono::seconds(1));
WssServer servers(ports, threads, server_crt, server_key);
serverResourceUploads(servers, upload_url);
serverResourceRenames(servers, rename_url);
serverResourceDeletes(servers, delete_url);
serverResourceLists(server, list_url);
thread server_threads([&server](){
//Start WS-server
server.start();
});
this_thread::sleep_for(chrono::seconds(1));
server_threads.join();
server_thread.join();
}
catch (json_parser_error& e)
{
cout << "json read or write error" << endl;
return -1;
}
catch (exception& e) {
cout << e.what()<< endl;
return -1;
}
catch (...) {
cout << "unknown error" << endl;
return -1;
}
return 0;
}