using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; namespace RemotingSamples { public class RemoteObject : MarshalByRefObject { ////////////////////////////////////////////////////////////////////////////// ///constructor public RemoteObject() { Console.writeline("Remote object activated"); } ////////////////////////////////////////////////////////////////////////////// ///return message reply public String ReplyMessage(String msg) { Console.WriteLine("Client : "+msg);//print given message on console return "Server : Yeah! I'm here"; } } }
csc /t:library /debug /r:System.Runtime.Remoting.dll remoteobject.cs
using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; namespace RemotingSamples { public class Server { ///////////////////////////////////////////////////////////////////////////// ///constructor public Server() { } ///////////////////////////////////////////////////////////////////////////// ///main method public static int Main(string [] args) { //select channel to communicate TcpChannel chan = new TcpChannel(8085); ChannelServices.RegisterChannel(chan); //register channel //register remote object RemotingConfiguration.RegisterWellKnownServiceType( Type.GetType("RemotingSamples.RemoteObject,object"), "RemotingServer", WellKnownObjectMode.SingleCall); //inform console Console.WriteLine("Server Activated"); return 0; } } }
csc /debug /r:remoteobject.dll /r:System.Runtime.Remoting.dll server.cs
using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using RemotingSamples; namespace RemotingSamples { public class Client { ///////////////////////////////////////////////////////////////////////////// ///constructor public Client() { } ////////////////////////////////////////////////////////////////////////////// ///main method public static int Main(string [] args) { //select channel to communicate with server TcpChannel chan = new TcpChannel(); ChannelServices.RegisterChannel(chan); RemoteObject remObject = (RemoteObject)Activator.GetObject( typeof(RemotingSamples.RemoteObject), "tcp://localhost:8085/RemotingServer"); if (remObject==null) Console.WriteLine("cannot locate server"); else remObject.ReplyMessage("You there?"); return 0; } } }
csc /debug /r:remoteobject.dll /r:System.Runtime.Remoting.dll client.cs
Build Your Own ASP.NET Website Using C# & VB.NET