[asio] Multithreaded UDP server

Hi, would it be possible to post multithreaded UDP server example? Some pointers on internet or just some tips how to build one? Best regards, -- Miroslav Beranič ml.

Hi, First, I think it's a good idea to give the list some hint on what you're trying to achieve, multithreading is not a narrow topic. Have you looked at the asio tutorials and examples? http://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio/tutorial/tuttimer5.... / Christian 2008/11/20 Miroslav Beranič ml. <miroslav.beranic@mibesis.si>
Hi,
would it be possible to post multithreaded UDP server example? Some pointers on internet or just some tips how to build one?
Best regards, -- Miroslav Beranič ml. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hi, I would like to do something like HTTP Server 3, An HTTP server using a single io_service and a thread pool calling io_service::run(). With difference it uses UDP and not TCP. Basically I need UDP server that is (/would be) able to accept connections on multiple threads. Server accepts command from client and does some work in the background. It needs to send : SUCCESS or FAILURE back to the client. I have read examples, tutorials about use of boost::asio::strand, I use it in TCP server. I am stuck with accepting connections with multiple threads... I hope I did narrow down the topic, or didn't I? And: What would be the most efficient way to use CPU power (MacPro Quad-Core) when working with ASIO (TCP, UDP, ...), here I am referring to example HTTP 2, HTTP 3 or some other design? BTW: Great, great work on ASIO and Boost as package... Best regards, Miroslav 2008/11/22 Christian Holmquist <c.holmquist@gmail.com>:
Hi,
First, I think it's a good idea to give the list some hint on what you're trying to achieve, multithreading is not a narrow topic.
Have you looked at the asio tutorials and examples?
http://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio/tutorial/tuttimer5....
/ Christian
2008/11/20 Miroslav Beranič ml. <miroslav.beranic@mibesis.si>
Hi,
would it be possible to post multithreaded UDP server example? Some pointers on internet or just some tips how to build one?
Best regards, -- Miroslav Beranič ml. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Miroslav Beranič ml. Mibesis, Miroslav Beranič s.p. +386(0)40/814-843 miroslav.beranic@mibesis.si http://www.mibesis.si

From: "Miroslav Beranič ml." <miroslav.beranic@mibesis.si>
I would like to do something like HTTP Server 3 ... With difference it uses UDP and not TCP. Basically I need UDP server that is (/would be) able to accept connections on multiple threads. ... I am stuck with accepting connections with multiple threads...
UDP is a connection-less protocol. There are no "accepting connections" with UDP. So there's still confusion as to what you're trying to do. With UDP you will need to create an endpoint with the port you're wanting to receive from, then create a socket with that endpoint, then fire off an async_receive_from (assuming you're wanting to do async), then do the appropriate processing when the receive_from completes. Take a look at the async_udp_server example. There's multiple ways to hook up multi-threading with the above, but I would recommend doing it with a single thread and extend it to multi-threaded only when you have a good understanding of the best multi-threading design for your needs. Opening and handling multiple UDP ports in a single thread is easy and efficient with the above approach, and you may not gain much (if anything) by multi-threading it. If the main amount of work and time is taken in the processing of the message (and not in the Asio / network handling), then I would recommend one thread for all of the UDP async reads (as mentioned above), then the async handler takes the incoming message / buffer and puts it on a queue. The queue could be serviced by a thread pool, sized / tuned for your needs. This isolates your multi-threaded design from your networking code, and makes it much more flexible. Cliff
participants (3)
-
Christian Holmquist
-
Cliff Green
-
Miroslav Beranič ml.