. A simple example of remoting communication mechanism in net

Source: Internet
Author: User
Tags sendmsg

. NET in remoting communication mechanism preface:

This procedure example realizes a simple remoting communication case

  This program uses language: C #

Compilation tool: vs2013 project file

Compilation environment:. NET 4.0

Program module:

    • Test tests
    • Talker
    • Server Side
    • Client Side
    • Source Code Engineering File download

Test testing Program:

Talker class:

1  Public class Talker:marshalbyrefobject 2     {3public         void talk (string  word)4         {5            System.Console.WriteLine (word); 6         }78     }

Server side:

1  //Register Channel2TcpServerChannel channel =NewTcpServerChannel ("Talkchannel",8090);3ChannelServices.RegisterChannel (channel,true);4 5             //registering a remote object6 RemotingConfiguration.RegisterWellKnownServiceType (7                 typeof(Talker),8                 "Talker",9WellKnownObjectMode.SingleCall);

Client side:

1    Public Partial classForm1:form2     {3         PrivateTalker _talk =NULL;4          PublicForm1 ()5         {6 InitializeComponent ();7         }8 9         Private voidBtnsend_click (Objectsender, EventArgs e)Ten         { One             if(BtnSend.Text.Equals ("Start")) A             { -Timer1. Enabled =true; -Btnsend.text ="End"; the             } -             Else -             { -Timer1. Enabled =false; +Btnsend.text ="Start"; -             } +         } A  at         Private voidSendmsg (stringmsg) -         { -             Try -             { -                 //manipulating remote Objects - _talk. Talk (msg); in                 stringNewLine = msg +Environment.NewLine; -Txtcontent.text = TxtContent.Text.Insert (0, newline); to             } +             Catch(Exception ex) -             { the MessageBox.Show (ex. Message); *             } $         }Panax Notoginseng  -         Private voidForm1_Load (Objectsender, EventArgs e) the         { +             Try A             { theTimer1. Interval = +; +                 //Register Channel -TcpClientChannel channel =NewTcpClientChannel (); $ChannelServices.RegisterChannel (channel,true); $                 //Get remote Objects -_talk = (Talker) Activator.GetObject (typeof(Talker),"Tcp://localhost:8090/talker"); -             } the             Catch(Exception ex) -             {Wuyi MessageBox.Show (ex. Message); the             } -         } Wu  -         Private voidTimer1_Tick (Objectsender, EventArgs e) About         { $ sendmsg (TxtWord.Text.Trim ()); -}

Source Code Engineering File Download:

Source code Engineering File Download Http://files.cnblogs.com/files/JiYF/RemotingSolution.rar

. A simple example of remoting communication mechanism in net

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.