Instantly detect client disconnection from server socket

后端 未结 14 1661
北恋
北恋 2020-11-22 09:27

How can I detect that a client has disconnected from my server?

I have the following code in my AcceptCallBack method

static Socket hand         


        
14条回答
  •  眼角桃花
    2020-11-22 09:47

    Using the method SetSocketOption, you will be able to set KeepAlive that will let you know whenever a Socket gets disconnected

    Socket _connectedSocket = this._sSocketEscucha.EndAccept(asyn);
                    _connectedSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1);
    

    http://msdn.microsoft.com/en-us/library/1011kecd(v=VS.90).aspx

    Hope it helps! Ramiro Rinaldi

提交回复
热议问题