.NET Remoting的新特性-IpcChannel(.NET Framework 2.0)

.NET FrameWoek2.0中,新添加一个IpcChannel,它是利用Windows的Ipc(进程间通讯)实现的一个Remoting的Channel,它的速度比Http或Tcp的Channel快很多,但它只能被用在本机不同应用程序域之间的通讯,所以,如果我们的客户端有可能与服务器端在同一个机器上运行时,可以通过注册IcpChannel来提高性能。
下面是一个简单的IpcChannel的示例:

ContractedBlock.gif ExpandedBlockStart.gif Using directives #region Using directives
InBlock.gif
InBlock.gif
using System;
InBlock.gif
using System.Collections.Generic;
InBlock.gif
using System.Text;
InBlock.gif
using System.Runtime.Remoting;
InBlock.gif
using System.Runtime.Remoting.Channels;
InBlock.gif
using System.Runtime.Remoting.Channels.Ipc;
InBlock.gif
ExpandedBlockEnd.gif
#endregion

None.gif
None.gif
namespace  TestIpcChannel
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
class Program
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
static void Main(string[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            IpcChannel myChannel 
= new IpcChannel("test");
InBlock.gif            ChannelServices.RegisterChannel(myChannel);
InBlock.gif            RemotingConfiguration.RegisterWellKnownServiceType(
typeof(RemObject), "RemObject.rem", WellKnownObjectMode.SingleCall);
InBlock.gif            
//服务注册结束,下面是客户端代码
InBlock.gif
            RemObject obj = (RemObject)(Activator.GetObject(typeof(RemObject), "Ipc://Test/RemObject.rem"));
InBlock.gif            obj.TestMethod();
InBlock.gif            Console.ReadLine();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
public class RemObject : MarshalByRefObject
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public void TestMethod()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Console.WriteLine(
"Hello IcpChannel!");
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif}

None.gif
为了便于大家读代码,该程序同时扮演服务器和客户端的角色,可以直接编译执行。

转载于:https://www.cnblogs.com/dahuaidan410/archive/2004/09/10/41726.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值