解决方案 »

  1.   

    socket 自身也有一个设置心跳包的功能呀。IOControl,你看下这个方法
      

  2.   

    看一下源码,帮助你理解一下public bool Poll(int microSeconds, SelectMode mode)
    {
        int num;
        if (this.CleanedUp)
        {
            throw new ObjectDisposedException(base.GetType().FullName);
        }
        IntPtr handle = this.m_Handle.DangerousGetHandle();
        IntPtr[] ptrArray = new IntPtr[] { (IntPtr) 1, handle };
        TimeValue socketTime = new TimeValue();
        if (microSeconds != -1)
        {
            MicrosecondsToTimeValue((long) ((ulong) microSeconds), ref socketTime);
            num = UnsafeNclNativeMethods.OSSOCK.select(0, (mode == SelectMode.SelectRead) ? ptrArray : null, (mode == SelectMode.SelectWrite) ? ptrArray : null, (mode == SelectMode.SelectError) ? ptrArray : null, ref socketTime);
        }
        else
        {
            num = UnsafeNclNativeMethods.OSSOCK.select(0, (mode == SelectMode.SelectRead) ? ptrArray : null, (mode == SelectMode.SelectWrite) ? ptrArray : null, (mode == SelectMode.SelectError) ? ptrArray : null, IntPtr.Zero);
        }
        if (num == -1)
        {
            SocketException socketException = new SocketException();
            this.UpdateStatusAfterSocketError(socketException);
            if (s_LoggingEnabled)
            {
                Logging.Exception(Logging.Sockets, this, "Poll", socketException);
            }
            throw socketException;
        }
        if (((int) ptrArray[0]) == 0)
        {
            return false;
        }
        return (ptrArray[1] == handle);
    }-------------------------------------------------------------------------------------------
    请为参加博客之星的我投上一票感激之至
      

  3.   

    MSDN注明了,当另一方由于网络原因或者网络被拔之类的情况下,Poll也是查不出来的
    http://msdn.microsoft.com/zh-tw/library/system.net.sockets.socket.poll(VS.90).aspx
    自己看第二个注意事项,还是得尝试发送零字节的数据才能“及时”知道