惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - Kriss Liu

绕开 CoreLab.MySql 验证 如何通过活动目录(ADSI)修改IIS6中的 Web 服务扩展 XMLDOM/XMLHTTP的跨域访问和页面代理 关于如何让页面同时下载多个文件的尝试 - Kriss Liu - 博客园 Remoting中的线程与网络通信内幕初探 基于强名称签名的代码访问保护及其改进 利用命名管道(Named Pipe)向Flash Player模拟Flash媒体文件 多样、互动的WinForm UI设计与开发思路(Flash、Html等) WinForm中设计时与DesignMode的区别 ServU插件设计 如何在C#中直接操作C++结构体 .NET中Flags枚举的使用 最近的计划。。VOS和DataSetBrowser。。 看完《仙剑奇侠传》前20集的一点牢骚。。 一套可嵌入或独立使用的翻页控件: WebPager(附源码) ASP.NET 2.0 中创建DataList子类控件时的一个错误 在.NET中使用DirectMusic 我与电脑的十年 关于 Windows Media DRM 0xC00D2840 错误
Remoting多个信道(Chennel)的注册问题
Kriss Liu · 2005-11-30 · via 博客园 - Kriss Liu

  一般情况下我们用Remoting一个信道应该就够用了,因为程序要么是客户端,要么是服务器端。但是有时候也会出现一个客户端需要连接多个服务器端的情况,或者一个程序既作为服务器端(针对内网),又作为客户端(针对外网)。这个时候就需要注册多个信道了。
  根据一般的经验,客户端信道和服务器端信道应该是不冲突的。但实际的情况呢?看一下以下的代码:

IChannel serverChannel = new TcpServerChannel( 5000 );
ChannelServices.RegisterChannel( serverChannel, 
true );

IChannel clientChannel 

= new TcpClientChannel();
ChannelServices.RegisterChannel( clientChannel );

  运行后会出现异常“信道 'tcp' 已注册。”(RemotingException)

  注册两个客户端信道也一样会出现这个错误:

IChannel channel1 = new TcpClientChannel();
ChannelServices.RegisterChannel( channel1, 
true );
IChannel channel2 
= new TcpClientChannel();
ChannelServices.RegisterChannel( channel2, 
true );

  开始我怀疑是端口冲突,给每个信道分别设置不同的端口:

Hashtable props1 = new Hashtable();
props1[
"port"= 5001;
IChannel channel1 
= new TcpClientChannel( props1, new BinaryClientFormatterSinkProvider() );
ChannelServices.RegisterChannel( channel1, 
true );
Hashtable props2 
= new Hashtable();
props2[
"port"= 5002;
IChannel channel2 
= new TcpClientChannel( props2, new BinaryClientFormatterSinkProvider() );
ChannelServices.RegisterChannel( channel2, 
true );

  错误依旧。想想也是,如果端口冲突,应该是这种错误:“通常每个套接字地址(协议/网络地址/端口)只允许使用一次。”(SocketException)
  再分析一下原来的错误:“信道 'tcp' 已注册。”。难道是信道的名字冲突?
  赶紧把channel的ChannelName打印出来看一下:
  Console.WriteLine( "The Default Channel Name is " + (new TcpClientChannel()).ChannelName );
  "The Default Channel Name is tcp"...

  问题找到。接下来要做的就是在注册不同信道的时候,显式指定其信道名称。ServerChannel和ClientChannel各有不同的方法,以下示例其一:

IChannel channel1 = new TcpClientChannel( "Channel1"new BinaryClientFormatterSinkProvider() );
ChannelServices.RegisterChannel( channel1, 
true );
IChannel channel2 
= new TcpClientChannel( "Channel2"new BinaryClientFormatterSinkProvider() );
ChannelServices.RegisterChannel( channel2, 
true );

  BTW:因为很少看到网上Remoting的文章提到多信道的注册,所以把这个贴出来。也许大家注册信道的时候就指定了名字,这样就不会有这个问题。 另外,以上均是在.NET 2.0平台上。

  MSDN上的相关说明:
  ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconchannels.htm
  "信道名称在应用程序域中必须是唯一的。例如,由于默认信道具有名称,因此,若要在一个应用程序域中注册两个 HttpChannel 对象,就必须在注册它们之前更改信道的名称。"