[Remoting]当client不复存在而RemoteObject并不知道时的处理办法
2005-05-19 01:17
363 查看
[Remoting]当client不复存在而RemoteObject并不知道时的处理办法
编写者:郑昀@ultrapower 20050518
问题:
“singleton服务中客户端意外退出或网络故障时,服务器端如何知道,并作相应的业务层处理”。
背后的故事:
对于这个问题,http://www.dotnetjunkies.com/Tutorial/BFB598D4-0CC8-4392-893D-30252E2B3283.dcik有一个描述,他针对这种情况“Item 3) The Remote Object Does Not Explicitly Know When A Client Is No Longer Around. ”说道:
这时候远端服务器端对象总会抛出System.Net.Sockets.SocketException异常,所有在这个dead client之后的client将永不会收到事件通知。这个原因是:If an invoked method throws an exception, the method stops executing, the exception is passed back to the caller of the delegate, and remaining methods in the invocation list are not invoked. Catching the exception in the caller does not alter this behavior
他给出的基本思路是:
The basic idea is that we
1) gain access to the multicast delegate instance that contains our event subscribers in its invocation list
2) loop through this invocation list and try to manually call invoke on each item
3) catch any exceptions from dead clients
4) remove dead client subscriptions from the invocation list
5) continue manually calling invoke on all the remaining items in invocation list.
那么就是轮循解决了:
(客户端靠不住,估计只能依靠服务器端主动了):
public delegate void DelegateUsed( parameter list );
public event DelegateUsed ExampleEvent;
public void RaiseExampleEvent( )
{
Delegate[] targets = DelegateUsed.GetInvocationList();
foreach( DelegateUsed client in targets )
{
try
{
// Callback to client...
client( parameter list of delegate );
}
catch
{
// Failed to callback to client, remove registered delegate.
RemoteFavoriteChanged -= client;
}
}
}
这样剔除那些不存在了的client。
编写者:郑昀@ultrapower
编写者:郑昀@ultrapower 20050518
问题:
“singleton服务中客户端意外退出或网络故障时,服务器端如何知道,并作相应的业务层处理”。
背后的故事:
对于这个问题,http://www.dotnetjunkies.com/Tutorial/BFB598D4-0CC8-4392-893D-30252E2B3283.dcik有一个描述,他针对这种情况“Item 3) The Remote Object Does Not Explicitly Know When A Client Is No Longer Around. ”说道:
这时候远端服务器端对象总会抛出System.Net.Sockets.SocketException异常,所有在这个dead client之后的client将永不会收到事件通知。这个原因是:If an invoked method throws an exception, the method stops executing, the exception is passed back to the caller of the delegate, and remaining methods in the invocation list are not invoked. Catching the exception in the caller does not alter this behavior
他给出的基本思路是:
The basic idea is that we
1) gain access to the multicast delegate instance that contains our event subscribers in its invocation list
2) loop through this invocation list and try to manually call invoke on each item
3) catch any exceptions from dead clients
4) remove dead client subscriptions from the invocation list
5) continue manually calling invoke on all the remaining items in invocation list.
那么就是轮循解决了:
(客户端靠不住,估计只能依靠服务器端主动了):
public delegate void DelegateUsed( parameter list );
public event DelegateUsed ExampleEvent;
public void RaiseExampleEvent( )
{
Delegate[] targets = DelegateUsed.GetInvocationList();
foreach( DelegateUsed client in targets )
{
try
{
// Callback to client...
client( parameter list of delegate );
}
catch
{
// Failed to callback to client, remove registered delegate.
RemoteFavoriteChanged -= client;
}
}
}
这样剔除那些不存在了的client。
编写者:郑昀@ultrapower
相关文章推荐
- [Remoting]当client不复存在而RemoteObject并不知道时的处理办法
- [Remoting]当client不复存在而RemoteObject并不知道时的处理办法
- 当client异常断开而RemoteObject并不知道时的处理办法
- 当 xml中存在命名空间,三种处理办法(dom4j)
- php SOAP 错误[Client] looks like we got no XML document 处理办法
- C#下载报错:An exception occurred during a WebClient request.,不知道如何处理。
- C#下载报错:An exception occurred during a WebClient request.,不知道如何处理。
- 单击事件和双击事件同时存在的处理办法
- 当xml中存在命名空间,三种处理办法(dom4j)
- php SOAP 错误[Client] looks like we got no XML document 处理办法
- ASP.NET弹出显示ex.Message异常信息 存在换行符和回车符处理办法。
- 复制分发过程存在异常,数据库日志爆增处理办法
- Android 获取服务器数据解析Text数据,存在htmel标签的处理办法
- DataGuard主备归档存在gap的处理办法
- 遇到百度网址安全中心提醒您该页面可能存在XXXXXX的处理解决办法
- 当xml中存在命名空间,三种处理办法(dom4j)
- 当xml中存在命名空间,三种处理办法(dom4j)
- eclipse利用svn插件导入项目后存在的环境问题处理办法。
- DataGuard主备归档存在gap的处理办法
- httpclient中getmethod方法的url参数如果含有中文的处理办法