0

I use the code for the boost::asio SSL Server from this official example. Everything works great as long as I use it like in the example with the console input in the send_request() function. My goal is to access the running client and send queries to the server.

My first attempt was to add a public method named request() to access the clients send method from the main method. If I ran the client, it stopped immediately. I assume that this was due to the asynchronous functions (maybe the sockets are closed before the server sends the response) and the now missing recursion (I've deleted the send_request() call in the receive_response() function).

My second attempt was to create the socket in the main method and pass it as an argument in the class. This also failed.

How can I achieve the desired functionality?

EDIT: Does the client have to reconnect to the server for each query?

  • The io_context will return when it has no work to do. But you [can keep it going](https://stackoverflow.com/questions/54751302/prevent-boostasioio-context-from-returning-when-there-is-no-more-work-to-do). But if you don't put it in its own thread, now it will block. Typically you set it off to do a job and you don't want it to return until the job is done. What is your objective? To wit, send your queries in the job. – lakeweb Jan 08 '22 at 21:05
  • My goal is to call methods of the running client to communicate with the server and then I want to work with the return values ​​of these methods. The blocking process loop of io_context.run (); I already noticed. I will test to call the io_context run() method in a new thread. Maybe it solves my problem. – Michael Schäfer Jan 08 '22 at 21:47
  • [This may help](https://stackoverflow.com/questions/63330104/how-to-use-boostbeast-download-a-file-no-blocking-and-with-responses#answer-63512751). I take it you will have a main thread that handles events. – lakeweb Jan 08 '22 at 21:56
  • @lakeweb Thanks. I will need some time to understand the code. – Michael Schäfer Jan 09 '22 at 11:39
  • Hi, and I hope you have [read this](https://www.boost.org/doc/libs/1_78_0/doc/html/boost_asio/overview/core.html). And consider your objective, even if you put the context in a thread, that is where the work should be done. Try not to write code where you _talk_ to your socket from the main thread. – lakeweb Jan 09 '22 at 18:11

0 Answers0