Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8079425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:05:47+00:00 2026-06-05T16:05:47+00:00

I tried to make an asynchronous UDP client using boost::asio I get some code

  • 0

I tried to make an asynchronous UDP client using boost::asio
I get some code on internet, and I managed to send message.
But my client didn’t received the message from the server ( and it works when i don’t use boost ).

Here’s my code

 class udp_async_client 
 {
 public:

   udp_async_client (boost::asio::io_service& io_service, std::string& host, std:: string port, char **av , int ac)
: reply ()
, _io_service (io_service)
, _sock (io_service, udp:: endpoint (udp:: v4 (), 0)) {

udp:: resolver resolver (_io_service);
udp:: resolver:: query query (udp:: v4 (), host, port);
udp:: resolver:: iterator endpoint_iterator = resolver.resolve (query);
sender_endpoint = *endpoint_iterator;

_io_service.run ();

//test request string                                                                                                                                                                                                                    
using namespace std;


std::string request = av[3];
for (int i = 4 ; i < ac ; ++i)
  {
    request += ";";
    request += av[i];
  }

std:: cout <<"Request is:" <<request <<std:: endl;



_sock.async_send_to (boost:: asio:: buffer (request.c_str(), request.length())
                     , sender_endpoint
                     , boost:: bind (&udp_async_client::handle_send_to_server
                                     , this, boost:: asio:: placeholders:: error
                                     , endpoint_iterator));

  }

 ~udp_async_client () {
_io_service.stop ();
  }

  void handle_receive_from (const boost::system::error_code& error,
                        size_t bytes_recvd) {}

  void handle_receive_from (const boost::system::error_code& error,
                        size_t bytes_recvd) {}

  void handle_send_to_server (const boost::system::error_code& e,
                          udp:: resolver:: iterator endpoint_iterator) {
std:: cout <<"Handle send to" <<std:: endl;
char reply [max_length] = {};
_sock.async_receive_from (
                          boost:: asio:: buffer (reply, max_length), sender_endpoint,
                          boost:: bind (&udp_async_client::handle_receive_from, this,
                                        boost:: asio:: placeholders:: error,
                                        boost::asio::placeholders::bytes_transferred));

std:: cout <<"Reply is:" <<reply <<std:: endl;
  }

private:
char reply [max_length];
boost::asio::io_service& _io_service;
udp:: socket _sock;
boost:: asio:: ip:: udp:: endpoint sender_endpoint;

};

and my main :

int main (int ac, char** av) {

  if (ac < 5) {
   std:: cerr <<"Usage: nonblocking_udp_echo_client <host> <port> <name> <name to reach> \n";
 return 1;
 }

  boost:: asio:: io_service io_service;
  std:: string host (av[1]);
  std:: string port (av[2]);

  while (true)
    {
     udp_async_client cli (io_service, host, port, av , ac);
     boost:: this_thread:: sleep (boost:: posix_time:: millisec (500));
   }
 return 0;
  }

I don’t know what i did wrong …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:05:49+00:00Added an answer on June 5, 2026 at 4:05 pm

    _io_service.run() is a blocking call. Your code is actually not passing that line until the stop is called on io_service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a library that uses Boost ASIO (UDP multicast, asynchronous) and
I'm trying to make an asynchronous HTTP GET request using Webclient, however, the registered
I tried to make a new bare git repository but I get this error:
I tried to make admin panel and I am using sessions , but have
I tried using make defconfig to compile the kernel, but as expected, it failed
I tried to make an independent copy of an array but couldnt get one.
I am using this piece of code to make text button on web page
I have this piece of code to make an asynchronous HTTP request: public static
Tried to make a little old school ajax (iframe-javascript) script. A bit of mootools
I tried to make an alert popup with A with: var a = \u0041;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.