Windows套接字随机接受和接收

时间:2018-02-21 13:36:32

标签: c++ sockets winsock

我刚刚完成了我的跨平台套接字包装器。它在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...

在这里,我们可以看到0.0.0.0:580300.0.0.0:580310.0.0.0:58032接受了3个连接。对于每个连接Recv,返回大量字节读取但实际缓冲区为空。

有什么可以导致这种行为导致我的研究的方向?

1 个答案:

答案 0 :(得分:3)

4294967295是-1转换为无符号。所以你得-1可能表示一些套接字错误,并将其视为无符号字节数。