Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK, I found a solution to this issue. Under linux it's not necessary, but under windows I discovered that if you are neither binding nor connecting, you must have transmitted <em>something</em> before you make the call to asynch_recieve_from(), the call to which is included within my this->asynch_receive() method.</p> <p>My solution, make a dummy transmission of an empty string immediately before making the asynch_receive call under windows, so the modified code becomes:</p> <pre><code>m_socketPtr-&gt;set_option(boost::asio::socket_base::broadcast(true)); // If no local port is specified, default parameter is 0 // If local port is specified, bind to that port. if(localPort != 0) { boost::asio::ip::udp::endpoint localEndpoint(boost::asio::ip::address_v4::any(), localPort); m_socketPtr-&gt;bind(localEndpoint); } if(m_forceConnect) m_socketPtr-&gt;connect(m_targetEndPoint); // A dummy TX is required for the socket to acquire the local port properly under windoze // Transmitting an empty string works fine for this, but the TX must take place BEFORE the first call to Asynch_receive_from(...) #ifdef WIN32 m_socketPtr-&gt;send_to(boost::asio::buffer("", 0), m_targetEndPoint); #endif this-&gt;AsyncReceive(); // Register Asynch Recieve callback and buffer m_socketThread = boost::shared_ptr&lt;boost::thread&gt;(new boost::thread(boost::bind(&amp;MyNetworkBase::RunSocketThread, this))); </code></pre> <p>It's a bit of a hack in my book, but it is a lot better than implementing all the requirements to defer the call to the asynch recieve until after the first transmission. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload