今天开发网络模型,又遇到了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.

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.


down vote favorite
#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?

解答:


down vote accepted

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.

2 down vote favorite

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.

4 down vote accepted

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.

关于socket-error-10054的一点认知相关推荐

  1. idhttp的socket error # 10054 错误的处理办法

    转自: http://www.2ccc.com/news/Html/?1034.html 核心提示:写了个程序,自动断开adsl重拨以后,就出现错误"Socket Error # 10054 ...

  2. socket error 10054错误出现的原因以及解决办法,全网最全没有之一

    套接字是客户端-服务器通信的端点. FTP socket error 10054指示远程主机已强制终止或重置FTP客户端的现有连接.并且,用户看到完整的错误消息,如下所示. Upload failed ...

  3. 关于socket error 10054

    前段时间我的一个小程序在日夜兼程的运行的时候,发现运行几天后就会出现socket error 10054,然后那个报错的URL就一直报socket error 10054.上网查了的各种都是说对方服务 ...

  4. socket error 10054错误出现的原因及解决办法,全网最全没有之一

    套接字是客户端-服务器通信的端点. FTP socket error 10054指示远程主机已强制终止或重置FTP客户端的现有连接.并且,用户看到完整的错误消息,如下所示. Upload failed ...

  5. 复现socket error 10054及理解

    对于这个错误码的解释网上有很多,就是链接被远程主机重置,说实话这句话说了和没说一样,根本不知道啥意思,于是就各种查 对于10054可能的出现原因,一个大佬总结的很好,我这里直接搬运过来 对端关闭了so ...

  6. Socket 错误一览表,Socket Error Code

    最近程序 出现 几次 Socket 错误, 为了便于 差错.. 搜了一些 贴在这里.. 出现网络联机错误Socket error #11001 表示您的计算机无法连上服务器,请检查您的Proxy设定以 ...

  7. python socket.error: [Errno 10054] 远程主机强迫关闭了一个现有的连接。问题解决方案

    python socket.error: [Errno 10054] 远程主机强迫关闭了一个现有的连接.问题解决方案: 前几天使用python读取网页.因为对一个网站大量的使用urlopen操作,所以 ...

  8. python socket.error: [Errno 10054] 解决方法

    python socket.error: [Errno 10054] 解决方法 参考文章: (1)python socket.error: [Errno 10054] 解决方法 (2)https:// ...

  9. linux socket errno 4,解决socket.error: [Errno 98] Address already in use问题

    刚刚开始使用flask框架写了两个小程序.然后我先访问了第一个"Hello,Web"的小程序,运行通过,然后想看看第二个inputname的程序是不是写对,但是linux报错: s ...

  10. c++ socket error 10038错误

    socket error 10038错误是说socket无效或者被kill掉了. 原因: 错误代码: int RecvThread(SOCKET* lpParameter,py::function c ...

最新文章

  1. 初探性能优化--2个月到4小时的性能提升!
  2. 干货丨入门机器学习,从搞懂这8大经典算法开始
  3. [转]Linux环境下段错误的产生原因及调试方法小结
  4. 清除number输入框的上下箭头
  5. 【转】四、关于如何使用软件库的一个技巧-避免重复配置属性表
  6. 一朵云重50万公斤,为什么掉不下来?
  7. python import sql脚本_13-模块介绍-import两种方式-py文件的两种用途-模块搜索路径-项目开发的目录规范...
  8. 【安全】phpldapadmin-1.2.3 界面使用
  9. JSP中鼠标禁用代码
  10. Spring Cloud Gateway (六) 自定义 Global Filter
  11. python修饰器_python修饰器
  12. C++中this指针小记
  13. 【IoT】BROADBAND POWERLINE COMMUNICATIONS NETWORK DESIGN:宽带电力线通信网络设计
  14. 使用IDEA创建Android项目
  15. maya2018安装教程
  16. 天池学习赛:保险反欺诈预测(附代码)
  17. ASP.NET 安全认证(三)
  18. A - Linearization of the kernel functions in SVM (模拟)
  19. Day644.Spring框架开发双刃剑 -Java业务开发常见错误
  20. UART通信可否只接VCC、RXD、TXD而不接GND?

热门文章

  1. 【StringUtils】
  2. ArcGIS教程:解决在mxd文件,定义投影之后,数据源还是的投影坐标系还是未发生改变的问题。
  3. 【计组】懂了,时钟周期、机器周期、指令周期、总线周期、存储周期。
  4. 朴素贝叶斯算法新闻文本分类
  5. java中getTime()
  6. vue 之url拼接 根据选择条件动态修改url地址
  7. 易语言c语言哪个做游戏脚本,易语言游戏脚本写法源码
  8. 最优化理论·非线性最小二乘
  9. 学习win32汇编指令:lea和offset
  10. 如何使用 开源硬件Banana PI BPI-R2‘s GPIO-s