除了用keepalive的方法之外,怎么样能够立即检测到socke已经断掉 socket断开 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 socket 自身也有一个设置心跳包的功能呀。IOControl,你看下这个方法 看一下源码,帮助你理解一下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);}-------------------------------------------------------------------------------------------请为参加博客之星的我投上一票感激之至 MSDN注明了,当另一方由于网络原因或者网络被拔之类的情况下,Poll也是查不出来的http://msdn.microsoft.com/zh-tw/library/system.net.sockets.socket.poll(VS.90).aspx自己看第二个注意事项,还是得尝试发送零字节的数据才能“及时”知道 大家来讨论存储过程,何时不宜采用存储过程? 大家看看2段代码有什么区别,我看了半天也没有看出来,未注销的是不对的,注销的正确 c#中如何调用调色板 有关DataGridView中邦定下拉框的问题! 菜鸟对C#中的委托和委托事件的一些疑问 Table??? 请教子表编辑 请问大家关于.NET在XP2下安装的问题 WINFORM 背景透明 个别机器出现 不透明情况 请问可能是哪方面的毛病呢? WebSerivce问题,各位高手进来看看帮我解决一下。 回归散分 + 提问:Unity的语法错误 Spring!!!!
{
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);
}-------------------------------------------------------------------------------------------
请为参加博客之星的我投上一票感激之至
http://msdn.microsoft.com/zh-tw/library/system.net.sockets.socket.poll(VS.90).aspx
自己看第二个注意事项,还是得尝试发送零字节的数据才能“及时”知道