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

查看:1907
本文介绍了套接字错误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上运行,客户端是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字节
send(socket,buffer,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天全站免登陆