Socket synchronous/Asynchronous vs. blocking/non-blocking differences

Source: Internet
Author: User

On the Internet to read a lot of answers, also did not find the appropriate, perhaps this article is not the appropriate answer:)

Synchronous and asynchronous are concerned with the message communication mechanism, while blocking non-blocking is concerned with the state of the program while waiting for the result (message, return value) of the call.

Synchronous/asynchronous is the way the API is notified by callers. Blocking/non-blocking is the way the API caller waits.

synchronous, asynchronous, and blocking, non-blocking are composite relationships.

So there are 4 ways:

    1. Synchronous blocking

    2. Synchronous non-blocking

    3. Asynchronous blocking

    4. Asynchronous non-blocking

------------------------------------------------------------------------

Recv and Recvfrom:

Recv only the function returns after receiving the message, this is blocking.

The Recvfrom returns immediately, which is non-blocking.

For recvfrom, how do I receive a message because the function returns immediately? There are 2 ways of doing this:

    1. Open a thread, keep the Select, this is synchronous

    2. With an asynchronous mechanism, a message is notified when the system receives a message, which is asynchronous .

It seems that the above description only three kinds, blocking, synchronous non-blocking, asynchronous non-blocking, why?

because generally, since the use of blocking, with synchronization is good, (generally) with async a bit redundant , because the caller knows already received, but also need system notification?

I think that's why it's easy to confuse these 2 sets of concepts (there are few asynchronous blocking patterns, and some scenarios may need to be used).

Socket synchronous/Asynchronous vs. blocking/non-blocking differences

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.