Advertisement

blocking sockets

Started by October 09, 2002 06:59 PM
2 comments, last by smokes 22 years, 3 months ago
I read in the much beloved winsock faq that blocking sockets should be avoided for a server application unless it is using multiple threads. Why is that? if you combine blocking sockets with the select call you can make a great server.. the sockets never block because you use select() to check if the desired operation could be completed, without the socket blocking. This way it is only select which block unless you set timeout to zero. The faq mentions using nonblocking sockets with the select() call.. I cannot see the advantage in this other than the added complexity of a state machine.
Using non-blocking sockets (with select) is just an extra precaution/saftey-net, to make sure the server never ever blocks.
Advertisement
Threads take up resources. High-performance servers require non-blocking I/O models such as overlapped I/O and port-completion I/O.

What will happen if 1000 users attemp to connect? Without a non-blocking I/O model, you would have to create and manage 1000 threads.

Kuphryn

[edited by - kuphryn on October 10, 2002 10:35:39 PM]
There are plenty of games out there that support over 500 players with blocking sockets, a select call, and a single thread.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

This topic is closed to new replies.

Advertisement