Answer the question
In order to leave comments, you need to log in
What is the difference between synchronous server and asynchronous server in boost?
Good time! I'm studying boost, and I can't understand what is the qualitative difference between an asynchronous server and a synchronous one?
asynchronous server
synchronous server
In synchronous, as soon as a message is received on the socket, a message is formed and sent to the client. everything is clear here.
With asynchronous it is not possible to understand yet. Who understands, please explain or tell me a resource where it is explained for mere mortals.
Thanks to!
Answer the question
In order to leave comments, you need to log in
At once I will make a reservation, I can be mistaken, I did not use boost asio
With synchronous everything is correct. In this case, clients are processed in turn.
With asynchronous otherwise.
1. In the tcp_server constructor, start_accept is called, which calls async_accept and returns control.
2. Then io_service.run() is called, apparently, somewhere inside it still accepts the connection and calls handle_accept, which was binned at start_accept and point 1.
3. handle_accept calls start, which calls async_write, i.e. does not wait for the data to be sent, but again immediately returns control. At the end of sending, handle_write
4 will be called. then again start_accept -> async_accept and return
Those. in the synchronous case, the second client will not connect until the first is fully answered
. In the asynchronous case, async_write is called, and before the end of the response to the first client, in principle, the second can already connect.
In general, the asynchronous method is needed for this, so that, having accepted a client connection, immediately start accepting the next one, and work with the first client separately.
What is the qualitative difference between an asynchronous server and a synchronous one?As far as I understand, the fundamental difference is who is involved in the transfer of data, the OS kernel or your application. In asynchronous (non-blocking) mode, you ask the OS to call some code on the occurrence of certain events, such as when a new client has joined, when data has been received from the client or sent to the client, and so on.
tell me a resource where it is explained for mere mortalsI am not a pro in this matter, I figured it out for myself at the office. documentation . I can also recommend a couple of video tutorials from mail.ru:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question