An existing connection was forcibly closed by the remote host

后端 未结 12 2098
说谎
说谎 2020-11-22 09:26

I am working with a commercial application which is throwing a SocketException with the message,

An existing connection was forcibly closed by the rem

12条回答
  •  醉梦人生
    2020-11-22 09:58

    This is not a bug in your code. It is coming from .Net's Socket implementation. If you use the overloaded implementation of EndReceive as below you will not get this exception.

        SocketError errorCode;
        int nBytesRec = socket.EndReceive(ar, out errorCode);
        if (errorCode != SocketError.Success)
        {
            nBytesRec = 0;
        }
    

提交回复
热议问题