.NET Remoting的新特性-IpcChannel(.NET Framework 2.0)
生活随笔
收集整理的這篇文章主要介紹了
.NET Remoting的新特性-IpcChannel(.NET Framework 2.0)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
.NET FrameWoek2.0中,新添加一個IpcChannel,它是利用Windows的Ipc(進程間通訊)實現(xiàn)的一個Remoting的Channel,它的速度比Http或Tcp的Channel快很多,但它只能被用在本機不同應(yīng)用程序域之間的通訊,所以,如果我們的客戶端有可能與服務(wù)器端在同一個機器上運行時,可以通過注冊IcpChannel來提高性能。
下面是一個簡單的IpcChannel的示例:
Using?directives#region?Using?directives
using?System;
using?System.Collections.Generic;
using?System.Text;
using?System.Runtime.Remoting;
using?System.Runtime.Remoting.Channels;
using?System.Runtime.Remoting.Channels.Ipc;
#endregion
namespace?TestIpcChannel
{
????class?Program
????{
????????static?void?Main(string[]?args)
????????{
????????????IpcChannel?myChannel?=?new?IpcChannel("test");
????????????ChannelServices.RegisterChannel(myChannel);
????????????RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemObject),?"RemObject.rem",?WellKnownObjectMode.SingleCall);
????????????//服務(wù)注冊結(jié)束,下面是客戶端代碼
????????????RemObject?obj?=?(RemObject)(Activator.GetObject(typeof(RemObject),?"Ipc://Test/RemObject.rem"));
????????????obj.TestMethod();
????????????Console.ReadLine();
????????}
????}
????public?class?RemObject?:?MarshalByRefObject
????{
????????public?void?TestMethod()
????????{
????????????Console.WriteLine("Hello?IcpChannel!");
????????}
????}
}
為了便于大家讀代碼,該程序同時扮演服務(wù)器和客戶端的角色,可以直接編譯執(zhí)行。
下面是一個簡單的IpcChannel的示例:
Using?directives#region?Using?directives
using?System;
using?System.Collections.Generic;
using?System.Text;
using?System.Runtime.Remoting;
using?System.Runtime.Remoting.Channels;
using?System.Runtime.Remoting.Channels.Ipc;
#endregion
namespace?TestIpcChannel
{
????class?Program
????{
????????static?void?Main(string[]?args)
????????{
????????????IpcChannel?myChannel?=?new?IpcChannel("test");
????????????ChannelServices.RegisterChannel(myChannel);
????????????RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemObject),?"RemObject.rem",?WellKnownObjectMode.SingleCall);
????????????//服務(wù)注冊結(jié)束,下面是客戶端代碼
????????????RemObject?obj?=?(RemObject)(Activator.GetObject(typeof(RemObject),?"Ipc://Test/RemObject.rem"));
????????????obj.TestMethod();
????????????Console.ReadLine();
????????}
????}
????public?class?RemObject?:?MarshalByRefObject
????{
????????public?void?TestMethod()
????????{
????????????Console.WriteLine("Hello?IcpChannel!");
????????}
????}
}
為了便于大家讀代碼,該程序同時扮演服務(wù)器和客戶端的角色,可以直接編譯執(zhí)行。
轉(zhuǎn)載于:https://www.cnblogs.com/dahuaidan410/archive/2004/09/10/41726.html
總結(jié)
以上是生活随笔為你收集整理的.NET Remoting的新特性-IpcChannel(.NET Framework 2.0)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 愈学习愈发现自己的无知
- 下一篇: 虽然现在没有闲也没有钱,还是建立了自己的