Boost logo

Boost Users :

Subject: Re: [Boost-users] Using boost::Asio for connected UDP socket
From: Charles Mills (charlesm_at_[hidden])
Date: 2012-08-27 22:51:26


I know nothing about asio but UDP is itself inherently connectionless. You
don't need multiple sockets or threads or the like to handle multiple
clients. Think of your mailbox (the old-fashioned one that gets paper mail):
no matter how many people send you letters, you have and need only one
mailbox. All the letters arrive there, in no particular order, and with no
relationship between one letter from your friend Joe and the next letter
from Joe. You can receive correspondence simultaneously from any number of
people with one mailbox. TCP is more like a telephone: if you want to talk
to ten people at once you need ten telephones (okay, yes, I know about
conference calls but you get what I am saying).

 

If you want to keep track of a "conversation" with individual senders then
you will need some sort of structure and logic inside your program to do so.

 

Again, I know nothing about asio but with native sockets you do get told the
"return address" (the sender's IP address) for each incoming "datagram" as
UDP messages are called.

 

One nice thing about UDP: if the sender sends a message ABC and then another
message DEF you will get two messages, one ABC and one DEF; unlike TCP,
where in theory you might get one message of ABCDEF or even one of AB and
one CDEF. (In UDP the two messages *might* arrive out of order, DEF and then
ABC; or conceivably not arrive at all.) Also, unlike TCP, the sender does
not receive any kind of an error for undeliverable messages. I can write a
program that sends UDP messages to random IP addresses and I will never
receive any error indication whatsoever.

 

Hope this helps,

 

Charles

From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Gheorghe Marinca
Sent: Monday, August 27, 2012 3:55 PM
To: boost-users_at_[hidden]
Subject: [Boost-users] Using boost::Asio for connected UDP socket

 

Hi,

I want to implement an UDP server and have problems on defining on how the
server handles coming concurrent udp "connections" from multiple clients.
What I basically want to implement is an DNS proxy.

Is there something equivalent to an tcp::acceptor for udp ? Looking over
asio docs I see:

template<
    typename Protocol
<http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/reference/Protocol
.html> ,
    typename SocketAcceptorService
<http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/reference/SocketAc
ceptorService.html> = socket_acceptor_service<Protocol>>
class basic_socket_acceptor :
  public basic_io_object< SocketAcceptorService >,
  public socket_base

For tcp we have following typedef:

typedef basic_socket_acceptor< tcp > acceptor;

Can I use basic_socket_acceptor with socket_acceptor_service<UDP> so that I
can create additional udp sockets for every udp client that wants to send
data to my server ?
I've observed that if I use async_receive_from on the same socket I receive
data from multiple clients making impossible exchanging data (read/write)
with multiple clients at the same time.

Any hints are appreciated.

-Ghita



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net