Archived

This topic is now archived and is closed to further replies.

Structural

Win32 networking & threading

Recommended Posts

Lo, At the moment I'm working on my first networking module and I have a question about the usage of threads in such a module. I'm using TCP for this whole thing as I want to guarantee the arrival of the packets. At the moment I have threaded the acceptance function (to accept new connections) and the receive function (to read all sockets). The latter function reads ALL active sockets in the same thread. My question is: would it be wise to create MULTIPLE threads that read the sockets? So, one thread for each socket? I don't want the stuff to block when a client goes tits up. Also, when sending data, do I want to do this in seperate threads? So, one thread for each socket to send data... Thanks for any answers and tips [edited by - Structural on May 26, 2003 3:24:46 AM]

Share this post


Link to post
Share on other sites
How many sockets will your application be using at once?

If you create a new thread for every socket, then you should not be using too many sockets at once, since threads are expensive.

If your application must handle many sockets at once (I would say more than about 20 or 30), then I recommend that you use asynchronous sockets.

Share this post


Link to post
Share on other sites