gpt4 book ai didi

c++ - Windows TCP 套接字超时 C++

转载 作者:可可西里 更新时间:2023-11-01 02:52:02 25 4
gpt4 key购买 nike

我有一个问题

如何知道客户端是否在指定时间内没有响应服务器?!

我使用的是线程而不是选择函数。

非常感谢您的帮助:)

谢谢。

最佳答案

您需要按如下方式查看[设置套接字选项][1]:

setsockopt(sockid, SOL_SOCKET, SO_RCVTIMEO,(char *)&tv,sizeof(struct timeval));

完成后,您可以在调用接收和/或发送函数时再次检查 SOCKET_ERROR。具体错误码可以调用WSAGetLastError获取。

这是其中一个潜在的错误代码:

WSAEWOULDBLOCK10035

Resource temporarily unavailable.

This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. It is a nonfatal error, and the operation should be retried later. It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a nonblocking SOCK_STREAM socket, since some time must elapse for the connection to be established.

关于c++ - Windows TCP 套接字超时 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22892088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com