开发者

How to call accept() with non-blocking sockets c++

开发者 https://www.devze.com 2023-02-12 01:02 出处:网络
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()(WSAEWOULDB

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消