Questions tagged [boost-asio]

Boost.Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.

Most programs interact with the outside world in some way, whether it be via a file, a network, a serial cable, or the console. Sometimes, as is the case with networking, individual I/O operations can take a long time to complete. This poses particular challenges to application development. The Boost.Asio library is intended for programmers using C++ for systems programming, where access to operating system functionality such as networking is often required.

More information on Boost.Asio can be found here:

Notable alternatives for Boost.Asio:

4582 questions
21
votes
2 answers

Https server with cpp-netlib

How can one use cpp-netlib to implement a HTTPS-server? cpp-netlib can be used as a HTTP server (see service selector, handler and main in my example code). With boost::asio setting up a SSL connection is not too hard (see my attempt at…
Kasper van den Berg
  • 8,951
  • 4
  • 48
  • 70
21
votes
2 answers

Most Efficient High-Performance Server Socket/Thread Design

I'm building an extremely high-performance piece of enterprise software, which will receive, handle, and respond to over 50,000 TCP requests per second. This will be spread over a number of Amazon EC2 servers, but I'd like to get a single server…
Harry
  • 863
  • 3
  • 10
  • 26
21
votes
1 answer

Why do we need to use boost::asio::io_service::work?

There is an example of using boost::asio. Why does this example use the boost::asio::io_service::work ? And why is srv.run (); not called to perform tasks in the threads? int main() { boost::asio::io_service srv; …
Alex
  • 12,578
  • 15
  • 99
  • 195
20
votes
1 answer

How to convert boost::asio::awaitable to std::future?

I have a function that returns boost::asio::awaitable. What is the idiomatic way to convert this awaitable to std::future?
Sogartar
  • 2,035
  • 2
  • 19
  • 35
20
votes
4 answers

Can`t really understand what the parameters for constructing tcp::resolver::query

I am starting Boost.Asio and trying to make examples given on official website work. here`s client code: using boost::asio::ip::tcp; int _tmain(int argc, _TCHAR* argv[]) { try { boost::asio::io_service io_service; …
chester89
  • 8,328
  • 17
  • 68
  • 113
20
votes
1 answer

How to turn URL into IP address using boost::asio?

So I need some way of turning given Protocol://URLorIP:Port string into string ip int port How to do such thing with boost ASIO and Boost Regex? Or is it possible - to get IP using C++ Net Lib (boost candidate) - notice - we do not need long…
Rella
  • 65,003
  • 109
  • 363
  • 636
20
votes
5 answers

Boost async_* functions and shared_ptr's

I frequently see this pattern in code, binding shared_from_this as the first parameter to a member function and dispatching the result using an async_* function. Here's an example from another question: void Connection::Receive() { …
David Schwartz
  • 179,497
  • 17
  • 214
  • 278
19
votes
7 answers

Creating a high-performance network server in C++

I need to create a network server in C++ for a trading application. This network server needs to perform the following tasks: handle authentication of clients and provide session id for each session. handle orders originating from the clients and…
Lazylabs
  • 1,414
  • 16
  • 23
19
votes
3 answers

alternatives to std::string to use with boost::asio

boost::asio's various read and write functions and methods accept boost::asio::buffer. According to buffer's documentation, a mutable std::string cannot be wrapped in boost::asio::buffer, and thus cannot be used for asio's read functions. This is…
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
19
votes
3 answers

Boost.Asio as header-only

I want to use ASIO library from Boost in my project. Its doc say it can be header-only if regex is not used and SSL not used. However, running bcp for asio pulls a very many libraies some of which are with sources so need compiling, bjam etc. Can I…
zaharpopov
  • 16,882
  • 23
  • 75
  • 93
19
votes
1 answer

how to verify client certificates using boost::asio SSL?

Below is the code snippet for SSL context initialization and verify callback registered. If I connect SSL client with proper certificates it verifies the certificate and works as expected. But if I connect client without any certificate then it…
Chirag Desai
  • 1,249
  • 1
  • 10
  • 22
19
votes
4 answers

boost::asio::ip::tcp::socket is connected?

I want to verify the connection status before performing read/write operations. Is there a way to make an isConnect() method? I saw this, but it seems "ugly". I have tested is_open() function as well, but it doesn't have the expected behavior.
coelhudo
  • 4,710
  • 7
  • 38
  • 57
19
votes
4 answers

How do you mock the time for boost timers?

If possible, how do you mock the time for the purpose of triggering boost timers in a unit test? For example, is it possible to achieve something like the following: #include #include #include…
Zero
  • 11,593
  • 9
  • 52
  • 70
18
votes
1 answer

boost::asio UDP broadcasting

I want to broadcast UDP messages to all computers in a local network using boost::asio. Working through the examples I came up with try { socket.open(boost::asio::ip::udp::v4()); boost::asio::socket_base::broadcast option(true); …
nikolas
  • 8,707
  • 9
  • 50
  • 70
18
votes
4 answers

Why can't std::bind and boost::bind be used interchangeably in this Boost.Asio tutorials

I was trying the differents tutorials in Boost.Asio documentation and tried to replace boost components with C++11 ones. However, I got an error using std::bind in Timer.5 - Synchronising handlers in multithreaded programs. Here is the code…
authchir
  • 1,605
  • 14
  • 26