This seems to work for me... Does anyone see any issues?
public bool IsConnected
{
get {return !(Socket.Poll(1, SelectMode.SelectRead)
&& m_socket.Available ==0)}
}
Can also be put into an extension method.
public static class SocketExtensions
{
public static bool IsConnected(this Socket @this)
{
return !(@this.Poll(1, SelectMode.SelectRead) && @this.Available == 0);
}
}
Now you can easily use it in your code dealing with sockets.
var mySocket = new Socket();
while(mySocket.IsConncted())
{
// Do Stuff
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…