Remote network communication from the client to the server, send messages and return Remote Messages.
Remote Object (remotetest) C # class library code section:
Using system;
Namespace remotetest
{
Public class testloader: marshalbyrefobject
{
Public testloader ()
{
String stringwrite = "stor load .";
Console. writeline (stringwrite );
}
Public String sayhello (string MSG)
{
Console. writeline ("message: {0}", MSG );
Console. writeline ("Welcome to message send systems ");
String STC = "hello from remote ";
Return STC;
}
}
}
The testloader class in the remotetest component inherits the system. delealbyrefobject class, allowing the client to access the remote object.
Server (server) command line application code:
Using system;
Using system. runtime;
Using system. runtime. remoting;
Using system. runtime. remoting. channels;
Using system. runtime. remoting. channels. TCP;
Using remotetest;
Namespace Server
{
Public class Program
{
Public static void main (string [] ARGs)
{
Tcpserverchannel channel = new tcpserverchannels (9932 );
Channelserv ices. registerchannel (Channel, false );
Remotingconfiguration. registerwellknownservicetype (typeof (testloader), "testloader", wellknownobjectmode. singlecall );
Console. writeline ("hello from server ");
Console. Readline ();
}
}
}
Note: Add reference component: system. runtime. remoting (same below ).
Client Command Line application code:
Using system;
Using system. runtime. remoting;
Using system. runtime. remoting. channels;
Using system. runtime. remoting. channels. TCP;
Using remotetest;
Namespace Client
{
Public class classclient
{
Public static void main (string [] ARGs)
{
String stringtcp = "TCP: // localhost: 9932/testloader ";
Testloader loader = (testloader) activator. GetObject (typeof (remotetest. testloader), stringtcp );
String MSG;
Console. Write ("enter message :");
MSG = console. Readline ();
Console. writeline ("message: {0}" + MSG );
String res = loader. sayhello (MSG );
Console. writeline (RES );
}
}
}
Here, the two lines declared by the new pipeline have been omitted.
Program debugging: Start the server and then start the client. Close the client after entering the value. The value is displayed on the server.