/// <summary>
/// Checks the connection state
/// </summary>
/// <returns>True on connected. False on disconnected.</returns>
static bool IsConnected()
{
if (_nSocket.Connected)
{
if ((_nSocket.Poll(0, SelectMode.SelectWrite)) && (!_nSocket.Poll(0, SelectMode.SelectError)))
{
byte[] buffer = new byte[1];
if (_nSocket.Receive(buffer, SocketFlags.Peek) == 0)
{
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
判断 TCPClient disconnect
最新推荐文章于 2024-10-23 01:34:26 发布