boost-asio

Loading CA certificate from memory

∥☆過路亽.° 提交于 2021-02-08 02:00:19
问题 I am trying to load CA certificate from memory instead of file. But I keep getting handshake error while connecting. The file loading works perfectly, memory loading fails. What am I missing? std::ifstream file("message_server_ca.crt"); std::vector<char> fileContents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); boost::asio::const_buffer buffer(&fileContents.at(0),fileContents.size()); bool useFile = false; // switch between file and memory loading. boost::asio:

Are multiple ASIO io_services a good thing?

旧巷老猫 提交于 2021-02-05 20:09:22
问题 I've begun using Boost.ASIO for some simple network programming, my understanding of the library is not a great deal, so please bear with me and my newbie question. At the moment in my project I only have 1 io_service object. Which use for all the async I/O operations etc. My understanding is that one can create multiple threads and pass the run method of an io_service instance to the thread to provide more threads to the io_service . My question: Is it good design to have multiple io_service

Are multiple ASIO io_services a good thing?

≯℡__Kan透↙ 提交于 2021-02-05 20:00:28
问题 I've begun using Boost.ASIO for some simple network programming, my understanding of the library is not a great deal, so please bear with me and my newbie question. At the moment in my project I only have 1 io_service object. Which use for all the async I/O operations etc. My understanding is that one can create multiple threads and pass the run method of an io_service instance to the thread to provide more threads to the io_service . My question: Is it good design to have multiple io_service

boost::asio::read function hanging

北慕城南 提交于 2021-02-05 09:12:09
问题 If someone could please help me out, I cannot understand how the boost::asio::read function works in boost asio. In boost's example they have it declare the buffer size before the message is received which makes no sense (how do I know how many bytes to read before I read the message?) I tried this code but it just hangs boost::asio::io_service io_service; tcp::resolver resolver(io_service); tcp::resolver::query query(tcp::v4(), "localhost", "3000"); tcp::resolver::iterator iterator =

WriteHandler from boost::asio::async_write doesn't work properly when connection is dropped (firewall / manual disconecting the network)

穿精又带淫゛_ 提交于 2021-02-05 08:14:09
问题 I've been trying to write a client-server application using boost::asio, overall the application works great but I've stumbled over a problem regarding the data provided by 'WriteHandler' ( async_write function) when the connoction (between client <> server) is droped by a firewalll or by manualy disabling a newtwork card. Here is the code snippet: void write(const CommunicatorMessage & msg, std::function<void(bool)> writeCallback) { io_service.dispatch( [this, msg, writeCallback]() { boost:

In the context of boost::asio, what is the metaphor behind the term “strand”?

半世苍凉 提交于 2021-02-05 05:55:11
问题 As a French native, and a boost::asio user, I have added the 'strand' word to my vocabulary (is a 'toron' in French), here an image of a rope made of three strands, an each one made of multiple others: But I do not understand the metaphor used by Christopher Kohlhoff, do you ? 回答1: A strand is a logical, sequential path. Even if many paths intertwine, the paths are continuous and unbroken, and logically distinct. This is what makes the metaphor work: even though many strands can be

Sending and receiving protobuf data over Socket via boost asio

大憨熊 提交于 2021-01-29 22:16:10
问题 I want to send Protobuf data from my server to my client thanks to a TCP socket. I tested my client and my server and the TCP connexion works. So I try to serialize my data and send it by using a streambuf. In my server : void SendData(protobufType data){ std::ostream ostream(&this->m_streambuf); data.SerializeToOstream(&ostream); std::cout<<"Send data"<< std::endl; boost::asio::write(this->m_socket, this->m_streambuf); } In my client : boost::asio::streambuf response; boost::asio::read

how do i return the response back to caller asynchronously using a final callback dispatched from on_read handler?

杀马特。学长 韩版系。学妹 提交于 2021-01-28 23:30:38
问题 I need to expose an async REST api for c++ clients, that internally uses boost::beast for sending REST requests / receiving responses. The starting point is http_client_async.cpp example. Now the client will pass a callback function using this async api, that needs to be called at the end of the REST operation from the on_read() handler[http_client_async.cpp], passing the full response back to the caller. How can i achieve this? 回答1: but is there any way to invoke thie _callback through asio

how do i return the response back to caller asynchronously using a final callback dispatched from on_read handler?

耗尽温柔 提交于 2021-01-28 22:45:16
问题 I need to expose an async REST api for c++ clients, that internally uses boost::beast for sending REST requests / receiving responses. The starting point is http_client_async.cpp example. Now the client will pass a callback function using this async api, that needs to be called at the end of the REST operation from the on_read() handler[http_client_async.cpp], passing the full response back to the caller. How can i achieve this? 回答1: but is there any way to invoke thie _callback through asio

How would I include asio library using CMake?

社会主义新天地 提交于 2021-01-28 22:20:20
问题 I am trying to work on a project for a class and I want to use CMake to build the project. My current project looks like |-bin |-CMakeLists.txt |-include |-asio-1.12.2 |-chat_message.hpp |-chat_message.cpp |-CMakeLists.txt |-src |-Server.cpp although my Server.cpp needs asio.hpp that is in /include/asio-1.12.2/include . The professor has a makefile that compiles it with the flags -DASIO_STANDALONE -Wall -O0 -g -std=c++11 -I./include -I./include/asio-1.12.2/include . My CMakeLists files look