Connect on "connection less" boost :: asio :: ip :: udp :: socket

Recently, I learned about UDP juice while browsing the network, and all the pages explaining this mention that UDP sockets are “less connected”. This, if I understand correctly, means that one does not have a “connection” between the two sockets, but instead it sends datagram packets to the specified endpoints, not knowing if it is listening to the other end.

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

  • async_connect: run asynchronous connect .
  • async_receive: start asynchronous reception on a connected socket .
  • async_send: start asynchronous sending on the connected socket .

Now this is a bit confusing for beginners. I can find 3 possible reasons for my confusion (in order of similarity :))

  • I'm missing something
  • The asio implementation does something behind the scenes to virtualize the connection.
  • Incorrect documentation

There is a slight glitch in the documents when you open the page for basic_datagram_socket :: async_connect in the example there is a TCP instance (instead of UDP ).

Will someone please enlighten me?

+6
source share
1 answer

There is a better explanation in the Single UNIX specification that connect for non-connected sockets:

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

+11
source

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


All Articles