套接字错误 10054
我有一个C/S程序。客户端使用套接字向服务器发送文件,在发送大约超过700k数据后,客户端(在win7上)将收到套接字10054错误,这意味着连接被对等方重置。
服务器运行在CentOS 5.4上,客户端是在virtual box中运行的windows7虚拟机。客户端和服务器通过虚拟网络接口进行通信。 命令端口(发送日志)正常,但数据端口(发送文件)有问题。 是否是由于套接字缓冲区大小配置错误或其他原因造成的? 如果有人可以帮我检查问题。谢谢。
每次我调用套接字时都会发送一个等于 4096 字节的缓冲区 send(socket, buffer, 4096, 0 )
CentOS 套接字配置。
#sysctl -a
...
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.tcp_mem = 196608 262144 393216
net.ipv4.tcp_dsack = 1
net.ipv4.tcp_ecn = 0
net.ipv4.tcp_reordering = 3
net.ipv4.tcp_fack = 1
我不太明白套接字缓冲区配置意味着什么,这是否会导致接收不完整结果的问题?
I have a C/S program. Client use socket to send a file to server, after send approximate more than 700k data, client(on win7) will receive a socket 10054 error which means Connection reset by peer.
Server worked on CentOS 5.4, client is windows7 virtual machine run in virtual box. client and server communicate via a virtual network interface.
The command port(send log) is normal, but the data port(send file) have the problem.
If it was caused by wrong configuration of socket buffer size or something else?
If anyone can help me check the problem. Thanks.
Every time I call socket send a buffer equals 4096 byte
send(socket, buffer, 4096, 0 )
CentOS socket config.
#sysctl -a
...
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.tcp_mem = 196608 262144 393216
net.ipv4.tcp_dsack = 1
net.ipv4.tcp_ecn = 0
net.ipv4.tcp_reordering = 3
net.ipv4.tcp_fack = 1
I'm not quite understand what the socket buffer configuration means, if this will cause the receive incomplete result problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这几乎肯定是您的代码中的错误。最有可能的是,一侧认为另一侧已超时,因此异常关闭连接。最常见的情况是,您调用接收函数来获取数据,但实际上您已经获取了该数据,只是没有意识到。因此,您正在等待已经收到的数据,因此超时。
例如:
1)客户端发送消息。
2) 客户端发送另一条消息。
3) 服务器读取了两条消息,但认为它只收到一条消息,因此发送确认。
4) 客户端收到确认,等待服务器永远不会发送的第二个确认。
5) 服务器等待它实际上已经收到的第二条消息。
现在服务器正在等待客户端,客户端也在等待服务器。服务器编码不正确,并且没有意识到它实际上一次性收到了两条消息。 TCP 不保留消息边界。
如果您告诉我更多有关您的协议的信息,我可能可以更详细地告诉您出了什么问题。什么构成消息?哪一方何时发送?有任何致谢吗?等等。
但简而言之,双方可能都在等待对方。
最有可能的是,连接被对等方重置是一种症状。您的问题出现,一侧超时并中止连接。这会导致另一端重置连接,因为另一端中止了连接。
It's almost definitely a bug in your code. Most likely, one side thinks the other side has timed out and so closes the connection abnormally. The most common way this happens it that you call a receive function to get data, but you actually already got that data and just didn't realize it. So you're waiting for data that you have already received and thus time out.
For example:
1) Client sends a message.
2) Client sends another message.
3) Server reads both messages but thinks it only got one, sends an acknowledge.
4) Client receives acknowledge, waits for second acknowledge which server will never send.
5) Server waits for second message which it actually already received.
Now the server is waiting for the client and the client is waiting for the server. The server was coded incorrectly and didn't realize that it actually got two messages in one go. TCP does not preserve message boundaries.
If you tell me more about your protocol, I can probably tell you in more detail what went wrong. What constitutes a message? Which side sends when? Are there any acknowledgements? And so on.
But the short version is that each side is probably waiting for the other.
Most likely, the connection reset by peer is a symptom. Your problem occurs, one side times out and aborts the connection. That causes the other side to get a connection reset because the other side aborted the connection.