在“较少连接"上连接boost :: asio :: ip :: udp :: socket [英] connect on "connection less" boost::asio::ip::udp::socket

查看:222
本文介绍了在“较少连接"上连接boost :: asio :: ip :: udp :: socket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近通过浏览网络来学习UDP套接字,所有解释它的页面都提到UDP套接字减少了连接".如果我正确理解的话,这意味着一个套接字在两个套接字之间没有连接",而是将数据报包发送到指定的端点,而又不知道另一端是否正在侦听.

I've been learning about UDP socket lately by browsing the net and all the pages that were explaining it were mentioning that UDP sockets are "connection less". This, if I understand it correctly means that one does not have a "connection" between two sockets but instead shoots datagram packets to specified endpoints without knowing whether the other end is listening.

然后我开始阅读boost :: asio :: ip :: udp :: socket

Then I go and start reading the boost::asio::ip::udp::socket docs and find that it mentions API like:

  • async_connect:启动异步连接.
  • async_receive:在已连接的套接字上启动异步接收.
  • async_send:在已连接的套接字上启动异步发送.
  • async_connect: Start an asynchronous connect.
  • async_receive: Start an asynchronous receive on a connected socket.
  • async_send: Start an asynchronous send on a connected socket.

现在,对于新手来说这有点令人困惑.我可以找到3个可能导致我困惑的原因(按可能性:))

Now this is a bit confusing for a novice. I can find 3 possible causes for my confusion (in order of likehood :) )

  1. 我想念一些东西
  2. asio实现正在幕后进行一些操作以虚拟化连接.
  3. 文档错误

打开

There is also a slight glitch in the docs, when you open the page for basic_datagram_socket::async_connect the example in there is instantiating TCP sockets (instead of UDP ones).

有人可以启发我吗?

推荐答案

Single UNIX规范对

The Single UNIX specification has a better explanation of what connect does for connection-less sockets:

如果发起套接字不是连接模式,则connect()会设置套接字的对等地址,但不会建立连接.对于SOCK_DGRAM套接字,对等地址标识所有数据报在后续send()调用中发送的位置,并限制远程发件人进行后续recv()调用.

If the initiating socket is not connection-mode, then connect() sets the socket's peer address, but no connection is made. For SOCK_DGRAM sockets, the peer address identifies where all datagrams are sent on subsequent send() calls, and limits the remote sender for subsequent recv() calls.

这篇关于在“较少连接"上连接boost :: asio :: ip :: udp :: socket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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