0

I'm making an (c++) application which is a websocket client and websocket server. To be able to do this, I'm using the library websocketpp. To make the application both a client and server, I want the endpoint1.run() and endpoint2.listen(port) to be multi-threaded. This is where something goes wrong.

Normally (single thread) I use: endpoint.listen(port); which works.

To make it into a multi-thread I use:

boost::thread t(boost::bind(&server::listen, &endpoint, port));
sleep(1);
cout << "After thread! \n";
t.join();

However, I get the error:

main.cpp:116: error: no matching function for call to ‘bind(<unresolved overloaded function type>, websocketpp::server*, uint16_t&)’

server::listen is an overloaded function, should I call it differently in bind?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Rogier
  • 346
  • 8
  • 19

2 Answers2

4

Take a look at the boost documentation. There is a good example.
You need to resolve the ambiguity by your self.

mkaes
  • 13,781
  • 10
  • 52
  • 72
0

For those who are still wondering how to implement this:

void(websocketpp::role::server<websocketpp::server>::*f)(uint16_t,size_t) = &websocketpp::role::server<websocketpp::server>::listen;

boost::thread t(f, &endpoint, port, 1); //No need to use boost::bind here

and after that call t.detach() or endpoint.stop() and t.join()

KillerFox
  • 53
  • 1
  • 6