是什么在TCP / IP套接字编程同步和异步传输之间的区别? [英] What is the difference between synchronous and asynchronous transmission in TCP/ IP socket programming?

查看:773
本文介绍了是什么在TCP / IP套接字编程同步和异步传输之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的C ++,我试图开发基于升压:: ASIO库中的客户端 - 服务器应用程序。我(还)没能正确理解同步和异步模式之间的区别。我有previously研究Web协议的服务,如HTTP和AJAX。从这个解释,很明显,HTTP是同步的,AJAX是异步的。是什么在同步和异步方面在TCP套接字通信有什么区别?和模式是从企业层面看多线程应用程序的开发,为什么好?

据我了解同步模式,一会儿客户端阻塞,直到它从服务器接收数据包/数据信息。和在异步模式下,客户端进行不阻塞当前操作另一个操作。这是为什么不同?是异步的代名词,UDP?看来,如果接收到传输确认它并不关心。


解决方案

  1. TCP传输始终是异步的。什么是同步或异步是API的行为。一个同步API做的事情,而你怎么称呼它,例如:当它完成发送()移动数据到TCP发送缓冲区和回报。当你调用它的异步API开始,独立执行返回后给你,叫你回来或提供interrogable通过手柄完成该通知。


  2. HTTP是同步的,你发送请求,接收响应,展示或处理响应,所有的顺序。


  3. Ajax是异步仅在于它在周边HTTP请求独立的页面请求/响应循环的操作感。这是术语的一个糟糕的选择。这本来是最好用的一个术语,如嵌套,带外,...


I am new to C++ and I am trying to develop a client-server application based on the boost::asio library. I am (still) not able to understand properly the difference between sync and async modes. I've previously studied web protocol services such as HTTP and AJAX. From this explanation, it's clear that HTTP is synchronous and AJAX is asynchronous. What is the difference in TCP socket communication in terms of sync and async? And which mode is better from the perspective of enterprise-level multi-threaded application development, and why?

As I understand synchronous mode, the client blocks for a while until it receives the packet/ data message from the server. And in async mode, the client carries out another operation without blocking the current operation. Why is this different? Is async synonymous with UDP? It seems it doesn't care if it receives transmission acknowledgement.

解决方案

  1. TCP transmission is always asynchronous. What's synchronous or asynchronous is the behaviour of the API. A synchronous API does things while you call it: for example, send() moves data to the TCP send buffer and returns when it is done. An asynchronous API starts when you call it, executes independently after it returns to you, and calls you back or provides an interrogable handle via which completion is notified.

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

  3. Ajax is asynchronous only in the sense that it operates independently of the page request/response cycle in the surrounding HTTP request. It's a poor choice of terminology. It would have been better to use a term like 'nested', 'out of band', ...

这篇关于是什么在TCP / IP套接字编程同步和异步传输之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆