Discussion:
[asio-users] Boost asio - udp server
Gheorghe Marinca
2012-08-28 08:38:29 UTC
Permalink
I saw the official async udp server example from boost doc. There you
create a single udp socket, bind it to a local port and do something like
this:

socket(ioService,
boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))

socket.async_receive_from(buffer(data, max_length), senderEndpoint,
boost::bind(&Request::HandleReceiveFrom, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));

How can I handle multiple concurrent udp connections from clients, because
if I try to create another socket using

socket(ioService,
boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))

i get bind errors because I already have a socket bound to the same port

Some more about the udp server I want to implement. I use my server as a
dns proxy. I want to handle multiple clients, proxy their requests, and
give answers back.
If I could use something like tcp acceptor, but for udp that would simplify
things as I see them now.

Best regards,
-Ghita
svante karlsson
2012-08-28 09:36:05 UTC
Permalink
UDP is connectionless
You will receive all data sent from all your clients on the same server port.

/svante
I saw the official async udp server example from boost doc. There you create
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(),
port))
socket.async_receive_from(buffer(data, max_length), senderEndpoint,
boost::bind(&Request::HandleReceiveFrom, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
How can I handle multiple concurrent udp connections from clients, because
if I try to create another socket using
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(),
port))
i get bind errors because I already have a socket bound to the same port
Some more about the udp server I want to implement. I use my server as a dns
proxy. I want to handle multiple clients, proxy their requests, and give
answers back.
If I could use something like tcp acceptor, but for udp that would simplify
things as I see them now.
Best regards,
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Gheorghe Marinca
2012-08-28 10:00:43 UTC
Permalink
So the way to go in this case is the remeber the sender endpoint
ip::udp::endpoint and when I want to replay to a particular client just
create a new udp socked constructed with sender endpoint ?
I guess I should not have issues with address reuse because the remote
endpoint / server ip/port pair is unique then.
Post by svante karlsson
UDP is connectionless
You will receive all data sent from all your clients on the same server port.
/svante
Post by Gheorghe Marinca
I saw the official async udp server example from boost doc. There you
create
Post by Gheorghe Marinca
socket(ioService,
boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(),
Post by Gheorghe Marinca
port))
socket.async_receive_from(buffer(data, max_length), senderEndpoint,
boost::bind(&Request::HandleReceiveFrom, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
How can I handle multiple concurrent udp connections from clients,
because
Post by Gheorghe Marinca
if I try to create another socket using
socket(ioService,
boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(),
Post by Gheorghe Marinca
port))
i get bind errors because I already have a socket bound to the same port
Some more about the udp server I want to implement. I use my server as a
dns
Post by Gheorghe Marinca
proxy. I want to handle multiple clients, proxy their requests, and give
answers back.
If I could use something like tcp acceptor, but for udp that would
simplify
Post by Gheorghe Marinca
things as I see them now.
Best regards,
-Ghita
------------------------------------------------------------------------------
Post by Gheorghe Marinca
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Green, Cliff
2012-08-28 16:01:58 UTC
Permalink
You do not need to create a socket for the reply - just send a datagram back to the source ("sent from") address. This is a pretty common use case.

Cliff

From: Gheorghe Marinca [mailto:***@gmail.com]
Sent: Tuesday, August 28, 2012 3:01 AM
To: asio-***@lists.sourceforge.net
Subject: Re: [asio-users] Boost asio - udp server

So the way to go in this case is the remeber the sender endpoint ip::udp::endpoint and when I want to replay to a particular client just create a new udp socked constructed with sender endpoint ?
Gheorghe Marinca
2012-08-28 17:43:19 UTC
Permalink
How to I send a datagram back without constructing a socket? What API to
use?
You do not need to create a socket for the reply – just send a datagram
back to the source (“sent from”) address. This is a pretty common use case.
****
** **
Cliff****
** **
*Sent:* Tuesday, August 28, 2012 3:01 AM
*Subject:* Re: [asio-users] Boost asio - udp server****
** **
So the way to go in this case is the remeber the sender endpoint
ip::udp::endpoint and when I want to replay to a particular client just
create a new udp socked constructed with sender endpoint ?
****
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Cliff Green
2012-08-28 17:52:35 UTC
Permalink
Use the UDP receive_from and send_to methods (the async versions have “async” in the method name).

Cliff


From: Gheorghe Marinca
Sent: Tuesday, August 28, 2012 10:43 AM
To: asio-***@lists.sourceforge.net
Subject: Re: [asio-users] Boost asio - udp server

How to I send a datagram back without constructing a socket? What API to use?

On Aug 28, 2012 7:07 PM, "Green, Cliff" <***@boeing.com> wrote:

You do not need to create a socket for the reply – just send a datagram back to the source (“sent from”) address. This is a pretty common use case.



Cliff



From: Gheorghe Marinca [mailto:***@gmail.com]
Sent: Tuesday, August 28, 2012 3:01 AM
To: asio-***@lists.sourceforge.net
Subject: Re: [asio-users] Boost asio - udp server



So the way to go in this case is the remeber the sender endpoint ip::udp::endpoint and when I want to replay to a particular client just create a new udp socked constructed with sender endpoint ?




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio




--------------------------------------------------------------------------------
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


--------------------------------------------------------------------------------
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Gheorghe Marinca
2012-08-28 18:56:25 UTC
Permalink
I do not find for some reason these non member functions in online
documentation.. That is without creating a udp socket.
Post by Cliff Green
Use the UDP receive_from and send_to methods (the async versions have
“async” in the method name).
Cliff
*Sent:* Tuesday, August 28, 2012 10:43 AM
*Subject:* Re: [asio-users] Boost asio - udp server
How to I send a datagram back without constructing a socket? What API to use?
You do not need to create a socket for the reply – just send a datagram
back to the source (“sent from”) address. This is a pretty common use case.
****
****
Cliff****
****
*Sent:* Tuesday, August 28, 2012 3:01 AM
*Subject:* Re: [asio-users] Boost asio - udp server****
****
So the way to go in this case is the remeber the sender endpoint
ip::udp::endpoint and when I want to replay to a particular client just
create a new udp socked constructed with sender endpoint ?
****
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
------------------------------
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Cliff Green
2012-08-28 22:02:41 UTC
Permalink
Method == member function (typical terminology). Here’s the web page:

http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/reference/ip__udp/socket.html

Cliff

From: Gheorghe Marinca
Sent: Tuesday, August 28, 2012 11:56 AM
To: asio-***@lists.sourceforge.net
Subject: Re: [asio-users] Boost asio - udp server

I do not find for some reason these non member functions in online documentation.. That is without creating a udp socket.

On Aug 28, 2012 9:12 PM, "Cliff Green" <***@codewrangler.net> wrote:

Use the UDP receive_from and send_to methods (the async versions have “async” in the method name).

Cliff


From: Gheorghe Marinca
Sent: Tuesday, August 28, 2012 10:43 AM
To: asio-***@lists.sourceforge.net
Subject: Re: [asio-users] Boost asio - udp server

How to I send a datagram back without constructing a socket? What API to use?

On Aug 28, 2012 7:07 PM, "Green, Cliff" <***@boeing.com> wrote:

You do not need to create a socket for the reply – just send a datagram back to the source (“sent from”) address. This is a pretty common use case.



Cliff



From: Gheorghe Marinca [mailto:***@gmail.com]
Sent: Tuesday, August 28, 2012 3:01 AM
To: asio-***@lists.sourceforge.net
Subject: Re: [asio-users] Boost asio - udp server



So the way to go in this case is the remeber the sender endpoint ip::udp::endpoint and when I want to replay to a particular client just create a new udp socked constructed with sender endpoint ?




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio




------------------------------------------------------------------------------
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


------------------------------------------------------------------------------
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio




--------------------------------------------------------------------------------
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


--------------------------------------------------------------------------------
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Jeff Koftinoff
2012-08-28 22:16:59 UTC
Permalink
You already have a UDP socket; the one the request was received from.

Jeff
Post by Cliff Green
I do not find for some reason these non member functions in online documentation.. That is without creating a udp socket.
Use the UDP receive_from and send_to methods (the async versions have “async” in the method name).
Cliff
From: Gheorghe Marinca
Sent: Tuesday, August 28, 2012 10:43 AM
Subject: Re: [asio-users] Boost asio - udp server
How to I send a datagram back without constructing a socket? What API to use?
You do not need to create a socket for the reply – just send a datagram back to the source (“sent from”) address. This is a pretty common use case.
Cliff
Sent: Tuesday, August 28, 2012 3:01 AM
Subject: Re: [asio-users] Boost asio - udp server
So the way to go in this case is the remeber the sender endpoint ip::udp::endpoint and when I want to replay to a particular client just create a new udp socked constructed with sender endpoint ?
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Gheorghe Marinca
2012-08-29 16:23:38 UTC
Permalink
Coming back to my udp server implementation. I read client requests on port
53 (DNS proxy), forward them to a name server and when that replay comes
back I want to replay to my clients using the same source port (53)
What I have been doing until now was to use only a socket on server (bound
to port 53) and receive all requests on that socket, but replayed to
clients using udp::socket::sent_to(clientEndpoint)

What happens is that clients outside of local machine (only) would not
recognize datagrams sent from my server to them because when I replay I use
a different source port than port 53 where they sent requests to.
It's something like that

D1(Source 192.168.1.1: port 1234, Destination server : port 53)
D2(Source server:* port 2331*, Destination 192.168.1.1: port 1234)

Is there a way to send clients response back without using the socket that
I originally received requests to ?
You do not need to create a socket for the reply – just send a datagram
back to the source (“sent from”) address. This is a pretty common use case.
****
** **
Cliff****
** **
*Sent:* Tuesday, August 28, 2012 3:01 AM
*Subject:* Re: [asio-users] Boost asio - udp server****
** **
So the way to go in this case is the remeber the sender endpoint
ip::udp::endpoint and when I want to replay to a particular client just
create a new udp socked constructed with sender endpoint ?
****
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Loading...