title: Send UDP packet to a public IP using Boost.asio
body: <p>I want to send UDP packets to my static IP <code>122.***.***.***</code> where an UDP server listens on port 1213. </p>
  
  <pre><code>udp::resolver resolver(io_serviceSend);
      udp::resolver::query query(udp::v4(),"122.***.***.***","1213");
      udp::endpoint receiver_endpoint = *resolver.resolve(query);
  
      udp::socket socket(io_serviceSend);
      socket.open(udp::v4());
  
      boost::shared_ptr&lt;std::string&gt; message(new std::string("Transfer"));
  
      socket.send_to(boost::asio::buffer(*message), receiver_endpoint);
  </code></pre>
  
  <p>but this fails. Is it because i am sending it to the private port rather than sending it to the NAT's port. but for TCP it works perfectly. 
  Can some one explain me the theory or post a good link.  </p>
  
  <p>and my server code is</p>
  
  <pre><code>UDPTunnel::UDPTunnel(boost::asio::io_service&amp; io_service)
  :socket_(io_service, udp::endpoint(udp::v4(), 1213))
  {
  start_receive();
  }
  
  void UDPTunnel::start_receive()
  {
      socket_.async_receive_from(
              boost::asio::buffer(recv_buffer_), remote_endpoint_,
              boost::bind(&amp;UDPTunnel::handle_receive, this,
              boost::asio::placeholders::error,
              boost::asio::placeholders::bytes_transferred));
      cout &lt;&lt; "\nUDP Started To Listening";
  }
  
  void UDPTunnel::handle_receive(const boost::system::error_code&amp; error,std::size_t)
  {
   cout &lt;&lt; "\nUDP Recieved Message";
   if (!error || error == boost::asio::error::message_size)
    {
    cout &lt;&lt; "\nRecieved Message";
    }
  </code></pre>
  
  <p>}</p>