Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

  • 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.

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

  1. I'm missing something
  2. The asio implementation is doing something behind the scenes to virtualize the connection.
  3. The documentation is wrong

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).

Would someone please enlighten me?

like image 843
Peter Jankuliak Avatar asked May 17 '12 22:05

Peter Jankuliak


1 Answers

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

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.

like image 86
cmeerw Avatar answered Sep 19 '22 07:09

cmeerw