Golang TCP错误 wsarecv

huangapple go评论83阅读模式
英文:

Golang TCP error wsarecv

问题

我正在编写一个应用程序,它监听 tcp 连接(参见这个示例)。当一个 tcp 连接 断开时,我得到了错误信息 read tcp ip_server.:port1->ip_client:port2: wsarecv: 远程主机强制关闭了一个现有的连接。
我预期会出现错误 EOF 和超时(对于 conn.SetReadDeadline()),并尝试使用以下代码捕获错误:

if err != nil {    	
	log.Println("从监听器获取错误")
    // 我认为,监听器可以继续处理其他情况
	if neterr, ok := err.(net.Error); ok && neterr.Timeout() || err == io.EOF {
		log.Println("关闭连接...")
		break // 连接将被关闭
	}
}

有人了解这个错误吗?你知道如何捕获这个错误以及何时会发生这个错误吗?提前谢谢!

英文:

I am writing an app which listens tcp connection (see this example) . When a tcp connection disconnected I got error read tcp ip_server.:port1->ip_client:port2: wsarecv: An existing connection was forcibly closed by the remote host.
I expected error EOF and timeout(for conn.SetReadDeadline()) and tried to catch error with this code:

if err != nil {    	
	log.Println("getting error from listener")
    // I thought, listener can continue work another cases
	if neterr, ok := err.(net.Error); ok && neterr.Timeout() || err == io.EOF {
		log.Println("Closing connection...")
		break // connection will be closed 
	}
}

Anyone knows about this error? Do you know how to catch this error and when this error will occured ? Thanks in advance !

答案1

得分: 7

这个错误通常是由于您在连接已被对方关闭后发送了数据引起的。换句话说,这是一个应用程序协议错误。

英文:

The usual cause of this error is that you sent data over a connection which had already been closed by the peer. In other words, an application protocol error.

huangapple
  • 本文由 发表于 2015年9月3日 18:48:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/32373537.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定