-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.cpp
59 lines (51 loc) · 2.29 KB
/
server.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
// Copyright Ben Pope 2017.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <pusher++/server.hpp>
#include <boost/program_options.hpp>
#include <iostream>
namespace
{
boost::program_options::variables_map parse_options(int argc, char* argv[])
{
boost::program_options::options_description desc{"Options"};
desc.add_options()
("app_id", boost::program_options::value<std::string>(), "Application ID")
("key", boost::program_options::value<std::string>(), "Application Key")
("secret", boost::program_options::value<std::string>(), "Secret")
("cluster", boost::program_options::value<std::string>()->default_value("mt1"), "Cluster: [ap1|ap2|eu|us2]mt1]")
("channel", boost::program_options::value<std::string>()->default_value("my-channel"), "Channel to publish to")
("event", boost::program_options::value<std::string>()->default_value("my-event"), "Event to publish to")
;
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);
if(!vm.count("app_id") || !vm.count("key") || !vm.count("secret"))
{
std::cout << desc << '\n';
std::exit(1);
}
return vm;
}
}
int main(int argc, char* argv[])
{
auto options = parse_options(argc, argv);
auto const app_id = options["app_id"].as<std::string>();;
auto const secret = options["secret"].as<std::string>();
auto const key = options["key"].as<std::string>();
auto const cluster = options["cluster"].as<std::string>();
auto const channel_name = options["channel"].as<std::string>();
auto const event_name = options["event"].as<std::string>();
boost::asio::io_service ios;
pusher::server<boost::asio::ip::tcp::socket> server{ios, app_id, key, secret, cluster};
server.connect();
std::string input;
while(input != "bye" && std::cout << "\nMessage: " && std::getline(std::cin, input))
{
std::cout << server.trigger(channel_name, event_name, input);
}
std::cout << '\n';
ios.run();
}