Example #1
0
 void receive_next() {
     m_multicast_socket.async_receive_from
         (boost::asio::buffer(m_frame_data, sizeof(m_frame_data)), m_frame_sender,
          boost::bind(&garmin_radar::handle_frame, this,
                      boost::asio::placeholders::error,
                      boost::asio::placeholders::bytes_transferred));
 }
Example #2
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 #3
0
 void start_receive(){
     socket.async_receive_from(
         boost::asio::buffer(recv_arr), receiver_endpoint,
         boost::bind(
             &sAudioReceiver::handle_receive,
             this,
             boost::asio::placeholders::error,
             boost::asio::placeholders::bytes_transferred
         )
     );
 }
Example #4
0
  void handle_receive_from(
      const boost::system::error_code& error,
      size_t bytes_recvd)
  {
    if (!error)
    {
      std::cout.write(data_, bytes_recvd);
      std::cout << std::endl;

      socket_.async_receive_from(
          boost::asio::buffer(data_, max_length), sender_endpoint_,
          boost::bind(&receiver::handle_receive_from, this,
              boost::asio::placeholders::error,
            boost::asio::placeholders::bytes_transferred));
    }
  }
Example #5
0
  receiver(boost::asio::io_service& io_service,
      const boost::asio::ip::address& listen_address,
      const boost::asio::ip::address& multicast_address)
    : socket_(io_service)
  {
    // Create the socket so that multiple may be bound to the same address.
    boost::asio::ip::udp::endpoint listen_endpoint(
        listen_address, multicast_port);
    socket_.open(listen_endpoint.protocol());
    socket_.set_option(boost::asio::ip::udp::socket::reuse_address(true));
    socket_.bind(listen_endpoint);

    // Join the multicast group.
    socket_.set_option(
        boost::asio::ip::multicast::join_group(multicast_address));

    socket_.async_receive_from(
        boost::asio::buffer(data_, max_length), sender_endpoint_,
        boost::bind(&receiver::handle_receive_from, this,
            boost::asio::placeholders::error,
            boost::asio::placeholders::bytes_transferred));
  }
Example #6
0
void DiscoveryServer::Listen() {
    m_socket.async_receive_from(
        boost::asio::buffer(m_recv_buffer), m_remote_endpoint,
        boost::bind(&DiscoveryServer::HandleReceive, this,
                    boost::asio::placeholders::error));
}