John Urberg
I'm using boost asio to send out multicast hailing messages every 15 seconds from an ActiveX control using boost 1.35.0 and VC9. I had a proof of concept ActiveX working fine, but in my production ActiveX, I'm able to send the first message successfully, but every subsequent message returns a 10009 error.
Here is the code:
MulticastServer::MulticastServer( boost::asio::io_service& io_service, string addr, int port, int seconds) : endpoint(boost::asio::ip::address::from_string(addr), port) , socket(io_service, endpoint.protocol()) , timer(io_service) , server_port(server_port) , seconds(seconds) { socket.set_option(boost::asio::ip::multicast::hops(32)); } void MulticastServer::Start() { HandleTimeout(boost::system::error_code()); } void MulticastServer::HandleTimeout(const boost::system::error_code& error) { string message = BuildHailMessage(); std::strcpy(buffer, message.c_str()); socket.async_send_to( boost::asio::buffer(buffer, message.length()), endpoint, boost::bind( &MulticastServer::HandleSendTo, this, boost::asio::placeholders::error)); } void MulticastServer::HandleSendTo(const boost::system::error_code& error) { timer.expires_from_now(boost::posix_time::seconds(seconds)); timer.async_wait(boost::bind(&MulticastServer::HandleTimeout, this, boost::asio::placeholders::error)); }
Any ideas what would cause this error message?
Also, if I use a string instead of char[] for the buffer, I always receive a 'string iterator not dereferencable' assertion failure. How could I fix that so I can use std::string instead of a char[] buffer?
Some more information. I tried using sync io and I don't have issues sending multiple times: while (1) { size_t rc = socket.send_to(boost::asio::buffer(buffer, message.length()), endpoint); std::cout << "Send to returned " << rc << std::endl; boost::this_thread::sleep(boost::posix_time::seconds(15)); } Here is how I'm starting the MulticastServer: void SocketClientConnector::Start(const string& connectionName) throw(exception) { this->name = connectionName; service_thread = new boost::thread(boost::bind(&SocketClientConnector::RunServiceThread, this)); } void SocketClientConnector::RunServiceThread() { try { MulticastServer server(io_service, group_address, group_port, server_port, name, id, interval); server.Start(); } catch (exception& e) { std::cout << e.what() << std::endl; } io_service.run(); } This is quite confusing for me as I pulled this code from the multicast_sender example and also had it working in a separate example ActiveX. The only thing I'm doing different is this code is located in a separate MFC DLL that is called from the ActiveX. Any ideas would be appreciated. Thanks, John