Golang TCP错误wsarecv

时间:2015-09-03 10:48:29

标签: tcp go

我正在编写一个倾听tcp connection的应用(请参阅this example)。当tcp connection断开连接后,我收到错误 read tcp ip_server.:port1->ip_client:port2: wsarecv: An existing connection was forcibly closed by the remote host. 我预计错误EOF和超时(对于conn.SetReadDeadline())并尝试使用此代码捕获错误:

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 
    }
}

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

1 个答案:

答案 0 :(得分:6)

此错误的常见原因是您通过已由对等方关闭的连接发送数据。换句话说,应用程序协议错误。