c++ - Windows套接字随机接受和接收

标签 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...

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

知道什么会导致这种行为来指导我的研究吗?

最佳答案

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

关于c++ - Windows套接字随机接受和接收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48907359/

相关文章:

c++ - 将字符串列表转换为 C 样式数组

c++ - 检测断开 Winsock C++

c++ - 在 C++ 中前向声明 typedef 结构

java - getInputStream() 什么时候返回 null?

c++ - ITK 从缓冲区导入图像数据

c++ - Qt5 有没有办法让 QLocalServer 监听抽象的 unix 套接字?

C++ 套接字问题

c - 发送一个内部带有 char 指针的结构?

c++ - 静态链接库不运行内部代码来设置静态变量

c++ - 编译时间一致的 char 类型哈希