Connection reset by peer的常见原因

简介:  Connection reset by peer的常见原因: 1)服务器的并发连接数超过了其承载量,服务器会将其中一些连接关闭;    如果知道实际连接服务器的并发客户数没有超过服务器的承载量,看下有没有网络流量异常。
 Connection reset by peer的常见原因:
1)服务器的并发连接数超过了其承载量,服务器会将其中一些连接关闭;
   如果知道实际连接服务器的并发客户数没有超过服务器的承载量,看下有没有网络流量异常。可以使用netstat -an查看网络连接情况。
2)客户端关掉了socket,而服务器还在给客户端发送数据;  这属于正常情况
3)防火牆的问题;
   如果网络连接通过防火牆,而防火牆一般都会有超时的机制,在网络连接长时间不传输数据时,会关闭这个TCP的会话,关闭后在读写,就会导致异常。 如果关闭防火牆,解决了问题,需要重新配置防火牆,或者自己编写程序实现TCP的长连接。实现TCP的长连接,需要自己定义心跳协议,每隔一段时间,发送一次心跳协议,双方维持连接。


常见网络异常(转自http://www.cnblogs.com/kaixin110/archive/2008/04/11/1148671.html):
第1个异常是java.net.BindException:Address already in use: JVM_Bind。该异常发生在服务器端进行new ServerSocket

(port)(port是一个0,65536的整型值)操作时。异常的原因是以为与port一样的一个端口已经被启动,并进行监听。此时用

netstat –an命令,可以看到一个Listending状态的端口。只需要找一个没有被占用的端口就能解决这个问题。


第2个异常是java.net.ConnectException: Connection refused: connect。该异常发生在客户端进行 new Socket(ip, port)

操作时,该异常发生的原因是或者具有ip地址的机器不能找到(也就是说从当前机器不存在到指定ip路由),或者是该ip存在

,但找不到指定的端口进行监听。出现该问题,首先检查客户端的ip和port是否写错了,如果正确则从客户端ping一下服务器

看是否能 ping通,如果能ping通(服务服务器端把ping禁掉则需要另外的办法),则看在服务器端的监听指定端口的程序是否

启动,这个肯定能解决这个问题。


第3个异常是java.net.SocketException: Socket is closed,该异常在客户端和服务器均可能发生。异常的原因是己方主动关

闭了连接后(调用了Socket的close方法)再对网络连接进行读写操作。


第4个异常是java.net.SocketException: (Connection reset或者 Connect reset by peer:Socket write error)。该异常

在客户端和服务器端均有可能发生,引起该异常的原因有两个,第一个就是如果一端的Socket被关闭(或主动关闭或者因为异

常退出而引起的关闭),另一端仍发送数据,发送的第一个数据包引发该异常 (Connect reset by peer)。另一个是一端退出

,但退出时并未关闭该连接,另一端如果在从连接中读数据则抛出该异常(Connection reset)。简单的说就是在连接断开后

的读和写操作引起的。


第5个异常是java.net.SocketException: Broken pipe。该异常在客户端和服务器均有可能发生。在第4个异常的第一种情况中

(也就是抛出SocketExcepton:Connect reset by peer:Socket write error后),如果再继续写数据则抛出该异常。前两个异

常的解决方法是首先确保程序退出前关闭所有的网络连接,其次是要检测对方的关闭连接操作,发现对方关闭连接后自己也要

关闭该连接。

  客户端错误代码10053 Software caused connection abort(软件原因导致连接中断)
目录
相关文章
|
网络安全 开发工具 git
git 出现错误:kex_exchange_identification: read: Connection reset by peer fatal
git 出现错误:kex_exchange_identification: read: Connection reset by peer fatal
git 出现错误:kex_exchange_identification: read: Connection reset by peer fatal
|
3月前
|
Go 开发工具 git
【git】解决:Failed to connect to 127.0.0.1 port 7890: Connection refused
【git】解决:Failed to connect to 127.0.0.1 port 7890: Connection refused
490 0
|
5月前
|
Java 网络安全 Docker
curl: (56) Recv failure: Connection reset by peer
curl: (56) Recv failure: Connection reset by peer
304 0
|
Python
ConnectionResetError: [Errno 104] Connection reset by peer
ConnectionResetError: [Errno 104] Connection reset by peer
469 0
|
数据安全/隐私保护
记录curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused解决方案
关于这个错误其实遇到过好多次了,基本都是在每次换电脑之后执行
记录curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused解决方案
|
运维 网络协议 网络安全
Closed socket connection for client /39.103.162.230:56100 (no session established for client)
Closed socket connection for client /39.103.162.230:56100 (no session established for client)
327 0
Closed socket connection for client /39.103.162.230:56100 (no session established for client)
|
网络协议 Java
filebeat:Failed to publish events caused by: write tcp 5044: write: connection reset by peer
filebeat:Failed to publish events caused by: write tcp 5044: write: connection reset by peer
329 0
filebeat:Failed to publish events caused by: write tcp 5044: write: connection reset by peer
执行HQL直接被退出:Remote side unexpectedly closed network connection
执行HQL直接被退出:Remote side unexpectedly closed network connection
1049 0
执行HQL直接被退出:Remote side unexpectedly closed network connection
|
网络协议
OGG-01232 Receive TCP params error: TCP/IP error 104 (Connection reset by peer), endpoint:
源端: 2015-02-05 17:45:49 INFO OGG-01815 Virtual Memory Facilities for: COM anon alloc: mmap(MAP_ANON) anon free: munmap file alloc: mmap(MAP_SH...
3054 0