It's because sockets are, by default, blocking. This means that calls to e.g. recv
will block until something is received. You can use the ioctlsocket
function to make the socket non-blocking.
You do have to be prepared that recv
can return with an WSAEWOULDBLOCK
error if nothing is available to be received. Or use polling functions such as select
to know when you have data that can be received. If you don't want to poll, search for "asynchronous sockets" on MSDN to find both server and client examples.