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

简介:
[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
目录
相关文章
|
2月前
|
XML Linux 数据格式
swing编写client端及多线程server端之client端
swing编写client端及多线程server端之client端
|
4月前
|
Java 应用服务中间件 Spring
WebService - CXF开发Server和Client(main方法测试)
WebService - CXF开发Server和Client(main方法测试)
40 0
|
消息中间件 前端开发 JavaScript
看得懂系列:Eureka Server 面向接口的方式读取配置文件
大家好,我是指北君。 PS:最近是跳槽的高峰期,我连日加班好多天,整理出了包含16000 多道面试题的面试宝典,并且指北君也会持续更新这份面试宝典中的题目,希望它能帮助大家找到自己心仪的工作!
看得懂系列:Eureka Server 面向接口的方式读取配置文件
【Groovy】使用 Groovy 语言开发服务器 Server 和客户端 Client 套接字程序 ( 客户端开发 )
【Groovy】使用 Groovy 语言开发服务器 Server 和客户端 Client 套接字程序 ( 客户端开发 )
165 0
|
存储 Java
【Groovy】使用 Groovy 语言开发服务器 Server 和客户端 Client 套接字程序 ( 服务器端开发 )
【Groovy】使用 Groovy 语言开发服务器 Server 和客户端 Client 套接字程序 ( 服务器端开发 )
125 0
HiveMQ web client客户端运行出错的错误分析
HiveMQ web client客户端运行出错的错误分析
113 0
HiveMQ web client客户端运行出错的错误分析
|
Web App开发 安全 .NET
艾伟_转载:WCF、Net remoting、Web service概念及区别
  Windows通信基础(Windows Communication Foundation,WCF)是基于Windows平台下开发和部署服务的软件开发包(Software Development Kit,SDK)。
1124 0
|
前端开发 .NET
一起谈.NET技术,Server-push技术(comet)----------asp.net中的异步处理+client与服务器端的长连接
  server-push技术已经面世很久了,但直到GTALK的诞生才慢慢的引导出这项技术,不过到现在为止,也很少有人去应用这方面的技术,server-push倒底是一个什么样的东西呢?   故名思义,server-push即“服务器推”的意思,ajax大家都用过,它和server-push是完全相反的两个东西,ajax是从服务器端拉取数据,如果要定期更新页面上显示的数据块,那么最简单的方法就是写个计时器,server-push则不同,它的本质是将client与server建立一个长连接,即连上后不断开,一旦服务器端有新的数据就将其推送到客户端,讲到这里出现了几个问题。
1218 0