Example #1
0
void STUNClient::sendTestRequest(
  boost::asio::ip::udp::socket& sock,
  OSS::IPAddress& dest,
  int testNum)
{
  //std::cout << "Sending TEST " << testNum << " " << sock.local_endpoint().address().to_string()
  //  << "->" << dest.toIpPortString() << std::endl;
  StunAtrString username;
  StunAtrString password;
  username.sizeValue = 0;
  password.sizeValue = 0;

  bool changePort=false;
  bool changeIP=false;

  switch (testNum)
  {
    case 1:
    case 10:
    case 11:
       break;
    case 2:
       //changePort=true;
       changeIP=true;
       break;
    case 3:
       changePort=true;
       break;
    case 4:
       changeIP=true;
       break;
    case 5:
       break;
    default:
       OSS_ASSERT(false);
  }

  StunMessage req;
  memset(&req, 0, sizeof(StunMessage));

  stunBuildReqSimple(&req, username, changePort , changeIP , testNum);

  char buf[STUN_MAX_MESSAGE_SIZE];
  int len = STUN_MAX_MESSAGE_SIZE;

  len = stunEncodeMessage(req, buf, len, password, false);

  sock.async_send_to(boost::asio::buffer(buf, len),
    boost::asio::ip::udp::endpoint(dest.address(), dest.getPort()),
    boost::bind(&STUNClient::handleWrite, shared_from_this(),
                      boost::asio::placeholders::error));

  sock.async_receive_from(boost::asio::buffer(_buffer), _senderEndPoint,
      boost::bind(&STUNClient::handleReadNatType, shared_from_this(),
        boost::asio::placeholders::error,
          boost::asio::placeholders::bytes_transferred));

  _semReadEvent.tryWait(10);
}
Example #2
0
 void send_request(){
     socket.async_send_to(boost::asio::buffer(send_arr, 5), receiver_endpoint,
         boost::bind(&sAudioReceiver::handle_send, this,
             boost::asio::placeholders::error,
             boost::asio::placeholders::bytes_transferred
         )
     );
 }