What is the difference between synchronous and asynchronous transmission in programming TCP / IP sockets?

I am new to C ++ and I am trying to develop a client-server application based on the boost :: asio library. I (still) am not able to correctly understand the difference between synchronization and asynchrony modes. I previously studied web protocol services such as HTTP and AJAX. From this explanation , it is clear that HTTP is synchronous and AJAX is asynchronous. What is the difference in TCP socket connection in terms of synchronization and asynchrony? And which mode is better from the point of view of developing multi-threaded applications at the enterprise level and why?

As I understand it, synchronous mode, the client blocks for a while until it receives a packet / data message from the server. And in asynchronous mode, the client performs another operation without blocking the current operation. Why is it different? Is UDP an asynchronous synonym? It does not seem to matter to him whether he receives confirmation of the transfer.

+6
source share
1 answer
  • TCP transmission is always asynchronous. What is a synchronous or asynchronous API behavior. The synchronous API does everything when you call it: for example, send() moves the data to the TCP send buffer and returns when it is done. The asynchronous API starts when you call it, runs independently after it returns to you, and calls you back or provides a request request through which completion notification is notified.

  • HTTP is synchronous in the sense that you send a request, receive a response, display or process the response, all in that order.

  • Ajax is asynchronous only in the sense that it works regardless of the page request / response cycle in the surrounding HTTP request. This is a poor choice of terminology. It would be better to use the term "nested", "out of range", ...

+9
source

Source: https://habr.com/ru/post/948758/


All Articles