P.S.: This is a way simpler program, which behaves in the same way: When
launching the thread before the async_send call it does not work - when
launching it after it does:
/* async_send_to udp example
* compile with
* g++ -o udpserver2 udpserver2.cpp -lboost_system -lboost_signals
-lboost_thread
*/
#include <iostream>
#include
void sender::sendIt(char *charBuffer){ [...] sj->dFC->io_service.run();
You should not call io_service::run() inside this function. The normal pattern is to set up your network code, e.g. from main(), and then call run() after setup. This call will block (and all Asio callbacks will be executed from this thread.) If you do not want your main thread to handle the network code, then you can launch in a separate thread (as previously suggested.)
Yes, I truly understand this but for some weired reason this doesn't work at all. In my case I launch the run function in the constructor of the main class right after the sender class had been instantiated:
SJ::SJ(){
/// SENDER INIT dFC->mySender = new sender(this);
boost::thread t = boost::thread(boost::bind(&boost::asio::io_service::run, &dFC->io_service)); t.join();
// OR dFC->io_service.run(); }
In there anything wrong with this ?
Thanks
Alex