如果以阻塞的方式使用UDP,几乎肯定要在一个线程中recvfrom,此时有可能出现错误10004,一个可能的原因是主线程先结束了。
下面是从网上找到的一点注释:
Answer/Solution:A blocking operation was interrupted by a call to WSACancelBlockingCall. An asynchronous signal (such as SIGINT or SIGQUIT) was caught by the process during the execution of an interruptible function. If the signal handler performs a normal return, the interrupted function call will seem to have returned the error condition.
Developer suggestions: You need to be prepared to handle this error on any functions that reference blocking sockets, or any calls to blocking functions, if you allow the user to cancel a blocking call. Whether to handle it as a fatal error or non-fatal error depends on the application and the context, so it's up to you to decide.