套接字错误 10054 [英] socket error 10054

查看:62
本文介绍了套接字错误 10054的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C/S 程序.客户端使用套接字向服务器发送文件,在发送大约超过 700k 个数据后,客户端(在 win7 上)将收到套接字 10054 错误,这意味着连接被对等方重置.

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.

服务器在 CentOS 5.4 上运行,客户端是运行在 virtual box 中的 windows7 虚拟机.客户端和服务器通过虚拟网络接口进行通信.命令端口(发送日志)正常,但数据端口(发送文件)有问题.如果它是由于套接字缓冲区大小配置错误或其他原因引起的?如果有人可以帮我检查问题.谢谢.

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.

每次我调用套接字发送一个缓冲区等于 4096 字节发送(套接字,缓冲区,4096,0)

Every time I call socket send a buffer equals 4096 byte send(socket, buffer, 4096, 0 )

CentOS 套接字配置.

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

我不太明白socket缓冲区配置是什么意思,如果这样会导致接收不完整的结果问题?

I'm not quite understand what the socket buffer configuration means, if this will cause the receive incomplete result problem?

推荐答案

这几乎肯定是代码中的错误.最有可能的是,一方认为另一方已超时,因此异常关闭连接.发生这种情况的最常见方式是您调用接收函数来获取数据,但您实际上已经获得了该数据并且只是没有意识到它.因此,您正在等待已收到的数据,因此会超时.

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.

例如:

1) 客户端发送消息.

1) Client sends a message.

2) 客户端发送另一条消息.

2) Client sends another message.

3) 服务器读取两条消息,但认为它只收到一条,发送确认.

3) Server reads both messages but thinks it only got one, sends an acknowledge.

4) 客户端收到确认,等待服务器永远不会发送的第二次确认.

4) Client receives acknowledge, waits for second acknowledge which server will never send.

5) 服务器等待它实际上已经收到的第二条消息.

5) Server waits for second message which it actually already received.

现在服务器在等待客户端,客户端在等待服务器.服务器编码不正确,并没有意识到它实际上一次收到了两条消息.TCP 不保留消息边界.

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.

这篇关于套接字错误 10054的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆