Re: [asio-users] Use multiple UDP sockets bound to same local server port
Brought to you by:
chris_kohlhoff
From: Alejandro S. <al...@al...> - 2012-09-04 05:22:25
|
You don't need multiple io_services. You can either: a) Run many threads from the same io_service, each thread calling io_service::run() as per HTTP Server example 3, b) Use one thread to read UDP data and implement your own producer/consumer scheme using good ol' pool of threads. On Tue, Sep 4, 2012 at 1:31 AM, Gheorghe Marinca <ghe...@gm...> wrote: > Well in case of tcp you have connections and when you accept communication > with a client happens on a newly created client server socket. In case of > udp that is a shared socket instance I cannot concurrently use same socket > for multiple send receive with multiple clients. So I would said that > decently that can affect scalability if I don't use multiple ioservice > threads as was suggested at some point. > > On Sep 4, 2012 6:48 AM, "Yuri Timenkov" <yu...@ti...> wrote: >> >> 2 sockets open with the same port (with reuse port/address option) may >> receive only broad/multicast packets. Unicast packet will be delivered to >> only one (usually last opened) socket. >> >> There is no such thing as "connection" for UDP. When you "connect" your >> udp socket you just set up a filter or default send_to address. But from >> network perspective you still have a single open port. You can receive and >> send packets from/to any address. >> >> I think you also misunderstand what receive_from does. The endpoint >> parameter is *output-only*. ASIO puts origin of received packet there and >> doesn't use it for input. >> >> As it was said many times in this list you should store this address/port >> combination in your own, user-space "session" and send response there later >> (when you receive your data) using async_send_to. >> >> I really don't understand why are you so concerned about scalability? Have >> you done any measurements? Web servers have only 1 socket open (on 80 port) >> and at the same time can handle lots of requests each second. It's not >> sockets you should worry about. >> How multiple sockets help you? In rough approximation you still have >> single network interface, single packets queue in OS kernel. Even if you >> send data to "different" sockets then packets still have to be put into >> single queue. If your handler is I/O-bound you should make it async to scale >> well. >> >> Regards, >> Yuri >> >> On Tue, Sep 4, 2012 at 12:50 AM, Gheorghe Marinca >> <ghe...@gm...> wrote: >>> >>> Thanks for prompt replay Jeff. I see that normal UDP API could use option >>> "reuse port" but ASIO only has >>> >>> boost::asio::socket_base::reuse_address >>> >>> >>> The problem with the approach mentioned by you is that in this case on >>> multiple clients requests (and time needed on each one for processing) I >>> cannot simultaneously "async_receive_from" (for reading more requests), >>> >>> >>> >>> and "async_send_to" (for sending back responses as they are available). >>> How I am going to have scalability ? >>> >>> Best regards >>> -Ghita >>> >>> >>> On Mon, Sep 3, 2012 at 11:34 PM, Jeff Koftinoff <je...@jd...> >>> wrote: >>>> >>>> Hello Ghita >>>> >>>> You are not to use different sockets for this purpose. >>>> >>>> You are not to use bind for sending to a client. >>>> >>>> You are to use send_to() with the existing server socket. One of the >>>> parameters of send_to() is the address of the client you are sending to. >>>> >>>> Remember that if you are using async_send_to() you can not call it again >>>> on the same socket until the first async_send_to() was signalled as >>>> completed. >>>> >>>> Regards, >>>> Jeff >>>> >>>> On 2012-09-03, at 1:29 PM, Gheorghe Marinca <ghe...@gm...> >>>> wrote: >>>> >>>> Hy. >>>> >>>> I've been looking for some days for a resolution to this. >>>> Is it possible to bind multiple sockets to same UDP server port ? If I >>>> use : >>>> >>>> socket(ioService, >>>> boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port)) >>>> >>>> >>>> >>>> >>>> >>>> and if I try to create another socket on same port (used for sending >>>> datagrams from same server port *but* to different clients endpoint) I get >>>> bind errors (asio throws exception) >>>> Is there a way to do this ? This must be a common use case, sending >>>> datagrams to multiple clients using same server port... >>>> >>>> Thanks >>>> -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 >>>> asi...@li... >>>> 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 >>>> asi...@li... >>>> 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 >>> asi...@li... >>> 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 >> asi...@li... >> 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 > asi...@li... > https://lists.sourceforge.net/lists/listinfo/asio-users > _______________________________________________ > Using Asio? List your project at > http://think-async.com/Asio/WhoIsUsingAsio > -- Alejandro Santos |