. 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