PDA

View Full Version : Handling multiple UDP sockets



ecphora
1st April 2006, 17:53
My Qt applications typically listen on several UDP sockets. Is it better to have a thread for each socket, or to have a single thread that does a select() on a fd_set of several sockets? Both approaches work, but I don't know which is more efficient.

wysota
1st April 2006, 17:56
There is no one proper answer to that question. select() in a single thread should be fine and in most cases more efficient than using multiple threads. Especially if processing time of the data received from the socket is short.

Zatraz
1st April 2006, 20:01
Each approach has its qualities and defects. The select one has speed but isi s more complex to program and have a hardcoded limit to how many sockets it can handle each time (the fd_set struct size).

I suggest you to look the "Unix Network Programming 3rd" book and accord with yout project choose the more suitable one.