Remote development of distributed C # programming instances

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.