using system; public class clock : marshalbyrefobject { public string getcurrenttime () { return datetime.now.tolongtimestring (); } } timeserver.cs
using system; using system.runtime.remoting; using system.runtime.remoting.channels; using system.runtime.remoting.channels.tcp; class myapp { static void main () { tcpserverchannel channel = new tcpserverchannel (1234); channelservices.registerchannel (channel);
console.writeline ("press enter to terminate..."); console.readline (); } } timeclient.cs
using system; using system.runtime.remoting; using system.runtime.remoting.channels; using system.runtime.remoting.channels.tcp; class myapp { static void main () { tcpclientchannel channel = new tcpclientchannel (); channelservices.registerchannel (channel);
public class clock : marshalbyrefobject { public string getcurrenttime () { return datetime.now.tolongtimestring (); } }
timeserver.cs
using system; using system.runtime.remoting;
class myapp { static void main () { remotingconfiguration.configure ("timeserver.exe.config"); console.writeline ("press enter to terminate..."); console.readline (); } } timeserver.exe.config
using system; public class stopwatch : marshalbyrefobject { datetime mark = datetime.now; public void start () { mark = datetime.now; } public int stop () { return (int) ((datetime.now - mark).totalmilliseconds); } } stopwatchserver.cs
using system; using system.runtime.remoting; using system.runtime.remoting.channels; using system.runtime.remoting.channels.tcp; class myapp { static void main () { tcpserverchannel channel = new tcpserverchannel (1234); channelservices.registerchannel (channel);
console.writeline ("press enter to terminate..."); console.readline (); } } stopwatchclient.cs
using system; using system.runtime.remoting; using system.runtime.remoting.channels; using system.runtime.remoting.channels.tcp; class myapp { static void main () { tcpclientchannel channel = new tcpclientchannel (); channelservices.registerchannel (channel); remotingconfiguration.registeractivatedclienttype (typeof (stopwatch), "tcp://localhost:1234"); stopwatch sw = new stopwatch (); sw.start (); console.writeline ("press enter to show elapsed time..."); console.readline (); console.writeline (sw.stop () + " millseconds"); } } 五、activator.getobject和activator.createinstance方法