IPCChannel是.NET Framework 2.0 里面新增的,它使用 Windows 进程间通信 (IPC) 系统在同一计算机上的应用程序域之间传输消息。在同一计算机上的应用程序域之间进行通信时,IPC 信道比 TCP 或 HTTP 信道要快得多。但是IPC只在本机应用之间通信。所以,在客户端和服务端在同一台机器时,我们可以通过注册IPCChannel来提高Remoting的性能。但如果客户端和服务端不在同一台机器时,我们不能注册IPCChannel。

下面让我们来看看如何使用IPCChannel:

首先我们定义一个RemotingObject类:

让.NET Remoting更快些-IPCChannel的实现[转]using System;
让.NET Remoting更快些-IPCChannel的实现[转]
让.NET Remoting更快些-IPCChannel的实现[转]
// 远程对象
让.NET Remoting更快些-IPCChannel的实现[转]
public class RemoteObject : MarshalByRefObject
}

接下来我们编写服务端代码:

让.NET Remoting更快些-IPCChannel的实现[转]using System;
让.NET Remoting更快些-IPCChannel的实现[转]
using System.Runtime.Remoting.Channels.Ipc;
让.NET Remoting更快些-IPCChannel的实现[转]
using System.Security.Permissions;
让.NET Remoting更快些-IPCChannel的实现[转]
让.NET Remoting更快些-IPCChannel的实现[转]
public class Server
}

客户端代码:

让.NET Remoting更快些-IPCChannel的实现[转]using System;
让.NET Remoting更快些-IPCChannel的实现[转]
using System.Runtime.Remoting.Channels.Ipc;
让.NET Remoting更快些-IPCChannel的实现[转]
using System.Security.Permissions;
让.NET Remoting更快些-IPCChannel的实现[转]
让.NET Remoting更快些-IPCChannel的实现[转]
public class Client
}

主要代码就算完成了。但,还有一个问题,那就是如果服务端和客户端在不同的Windows帐户运行的时候,会有验证权限的问题。对于这个问题,我们只要把服务端的信道注册代码改一下就好了:

让.NET Remoting更快些-IPCChannel的实现[转]Hashtable ht = new Hashtable();
让.NET Remoting更快些-IPCChannel的实现[转]ht[
"portName"= "TestChannel";
让.NET Remoting更快些-IPCChannel的实现[转]ht[
"name"= "ipc";
让.NET Remoting更快些-IPCChannel的实现[转]ht[
"authorizedGroup"= "Everyone";
让.NET Remoting更快些-IPCChannel的实现[转]serverChannel
= new IpcChannel(ht, null, provider);

相关文章:

  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2022-12-23
  • 2021-08-05
  • 2022-12-23
猜你喜欢
  • 2021-07-08
  • 2021-12-26
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
相关资源
相似解决方案