Reputation: 4273
I am setting the on-message handler like this and it works.
srv.set_message_handler(&on_message);
// This works
void on_message(websocketpp::connection_hdl hdl, server::message_ptr msg_ptr)
{
}
However, when I create a class and put the on_message
function in that class and try to set_message_handler
I get an error. The srv
variable in this case is a class member. Something like this:
class Server
{
public:
typedef websocketpp::server<websocketpp::config::asio> server;
void on_message(websocketpp::connection_hdl hdl,
server::message_ptr msg_ptr);
private:
server srv;
};
Error:
C:\Users\Shiro\ClionProjects\Thesis\source_files\Server.cpp: In constructor 'Server::Server(short unsigned int, const Graph&, const Graph&)':
C:\Users\Shiro\ClionProjects\Thesis\source_files\Server.cpp:10:37: error: no matching function for call to 'websocketpp::server<websocketpp::config::asio>::set_message_handler(void (Server::*)(Server::connection_handler, Server::message_ptr))'
s.set_message_handler(&on_message);
^
How can I work this out ? I want my on_message
function to be inside a Server
class.
Upvotes: 0
Views: 2169
Reputation: 4273
Doing it like this solved the problem:
// using boost::bind
server.set_message_handler(bind(&on_message, this, ::_1, ::_2));
Upvotes: 3