This my be a silly question, but I'm trying to use non-blocking sockets for the first time,but what I noticed is that when I run the server program it imediately gives me error in accept()
(WSAEWOULDBLOCK
, what i have read, 开发者_如何学编程this is an usual thing). My question is then,how can I connect to the server then ?
I am using ioctlsocket
in Windows. Thanks.
By using non-blocking sockets, accept()
will immediately return if there's no client connection waiting. You need to check if the error is WSAEWOULDBLOCK
, ignore it if it is, and use a polling loop to check again later. The select
function may be useful.
精彩评论