我刚刚完成了我的跨平台套接字包装器。它在 Linux 上运行良好,但在 Window 上我得到一个非常奇怪的行为。
当我启动服务器时(在环回端口 4242 上),程序开始接受来自随机源的连接并从这些连接接收数据。
我的终端中记录的内容示例(这以非常高的速度连续发生):
New client connected : 0.0.0.0:58030
Forwarding connection to worker in threadpool...
Waiting for client request...
New client connected : 0.0.0.0:58031
Received 4294967295 bytes from client ''
Forwarding connection to worker in threadpool...
Waiting for client request...
New client connected : Waiting for client request...
Received 4294967295 bytes from client ''0.0.0.0:Received 4294967295 bytes from client ''
58032
Waiting for client request...
Waiting for client request...
Received 4294967295 bytes from client ''
Received 4294967295 bytes from client ''Forwarding connection to worker in threadpool...
在这里我们可以看到接受了 3 个连接,形式为 0.0.0.0:58030
、0.0.0.0:58031
和 0.0.0.0:58032
.对于每个连接,Recv
返回大量读取的字节,但实际缓冲区为空。
知道什么会导致这种行为来指导我的研究吗?
最佳答案
4294967295 是 -1 转换为无符号。所以你得到 -1 可能表示一些套接字错误,并将其视为无符号字节数。
关于c++ - Windows套接字随机接受和接收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48907359/