Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
subprotocol_server.cpp
Go to the documentation of this file.
1#include <iostream>
2
5
7
9using websocketpp::lib::placeholders::_1;
10using websocketpp::lib::placeholders::_2;
11using websocketpp::lib::bind;
12using websocketpp::lib::ref;
13
14
17
18 std::cout << "Cache-Control: " << con->get_request_header("Cache-Control") << std::endl;
19
20 const std::vector<std::string> & subp_requests = con->get_requested_subprotocols();
21 std::vector<std::string>::const_iterator it;
22
23 for (it = subp_requests.begin(); it != subp_requests.end(); ++it) {
24 std::cout << "Requested: " << *it << std::endl;
25 }
26
27 if (subp_requests.size() > 0) {
28 con->select_subprotocol(subp_requests[0]);
29 }
30
31 return true;
32}
33
34int main() {
35 try {
36 server s;
37
38 s.set_validate_handler(bind(&validate,ref(s),::_1));
39
40 s.init_asio();
41 s.listen(9005);
42 s.start_accept();
43
44 s.run();
45 } catch (websocketpp::exception const & e) {
46 std::cout << e.what() << std::endl;
47 }
48}
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
Definition endpoint.hpp:643
void set_validate_handler(validate_handler h)
Definition endpoint.hpp:317
virtual char const * what() const
Definition error.hpp:263
Server endpoint role based on the given config.
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
bool validate(server &s, connection_hdl hdl)
int main()
websocketpp::server< websocketpp::config::asio > server
char * s