[Remoting]当client不复存在而RemoteObject并不知道时的处理办法

news/2024/7/3 20:01:41
[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


[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


[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


[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


[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



http://www.niftyadmin.cn/n/3649427.html

相关文章

Windows 10搭建Java开发平台——Java 8

Java是一门面向对象编程语言,不仅吸收了C语言的各种优点,还摒弃了C里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,…

连接到外部sql server工具类

首先第一步:我们需要下载一个jtds驱动让Android连接数据库 jtds下载地址:http://sourceforge.net/projects/jtds/files/ 第二步:数据库连接和测试类DataBaseUtil.java public class DataBaseUtil {private static Connection getSQLConnec…

什么是用户体验地图?该如何绘制?

什么是用户体验地图? 就像打仗需要地形图,体验提升的战斗也需要一个蓝图来规划和指引。 用户体验地图(Experience Maps)也被称为使用者旅程图(User Journey Map)。 用直白的话来解释下:用户体验地图就是通过一张图,用一种讲故事的…

如何在Ubuntu 18.04上使用复制迁移Redis数据

介绍 (Introduction) Redis is an in-memory, key-value data store known for its flexibility, performance, wide language support, and built-in features like replication. Replication is the practice of regularly copying data from one database to another in ord…

Android打开微信等其他应用

打开110String phoneNumber "120";Intent intentPhone new Intent(Intent.ACTION_CALL, Uri.parse("tel:" phoneNumber));startActivity(intentPhone);打开微信{Intent intent new Intent();ComponentName cmp new ComponentName("com.tencent.m…

解决eclipse中logcat不显示log的问题

调试程序需要打印一些消息出来,logcat不好用的话就很麻烦了。这个问题折腾了好久,为啥就是不出来呢? 上网找了很多解决办法: 重启eclipse 重启adb 重启logcat ......等等好多 都没能解决我的问题。英文水平有限一般小问题就问百度…

最好用的Windows 10终端——FluentTerminal

Windows 10自带的终端太丑 Windows 10的终端界面设计的如此丑,无论是cmd,powershell 还是wsl。默认的颜色和字体都非常难看。虽然进行一些颜色的设置可以改善视觉效果,但是十分麻烦,而且最奇怪的是设置不能同步到不同的快捷方式。…