赞
踩
using System; public class RemoteObject : MarshalByRefObject { public RemoteObject() { Console.WriteLine("Constructor called"); } public string Greeting(string name) { Console.WriteLine("Greeting called"); return "Hello," + name; } } |
using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Ipc; public class Server { public static void Main(string[] args) { //Instantiate our server channel. IpcServerChannel channel = new IpcServerChannel("ServerChannel"); //Register the server channel. ChannelServices.RegisterChannel(channel, false); //Register this service type. RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "RemoteObject", WellKnownObjectMode.SingleCall); Console.WriteLine("press return to exit"); Console.ReadLine(); } } |
using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Ipc; public class Client { public static void Main(string[] args) { //Create an IPC client channel. IpcClientChannel channel = new IpcClientChannel(); //Register the channel with ChannelServices. ChannelServices.RegisterChannel(channel, false); RemoteObject obj = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "ipc://ServerChannel/RemoteObject"); if (obj == null) { Console.WriteLine("could not locate server"); return; } for (int i = 1; i < 5; i++) { Console.WriteLine(obj.Greeting("mmpire")); } } } |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。