Remoting application instance + code, remoting application instance

Source: Internet
Author: User

Remoting application instance + code, remoting application instance

The following describes a small Remoting instance. The main function is to write client data to the server.

Analysis diagram:

The program code is two console applications (one client and one server) and one class library, as shown below.

Client code:

Using RemotingObjects; using System. collections. generic; using System. linq; using System. runtime. remoting. channels; using System. runtime. remoting. channels. tcp; using System. text; namespace RemotingClient {class Program {static void Main (string [] args) {TcpChannel channel = new TcpChannel (); ChannelServices. registerChannel (channel, false); WriteFileToLocal wfobj = (WriteFileToLocal) Activator. getObject (typeof (RemotingObjects. process), "tcp: // localhost: 8085/RemotingWriteFileToLocalService"); if (wfobj = null) {Console. writeLine ("Couldn't create Remoting Object 'writefiletolocal '. ");} else {Console. writeLine ("Please enter content:"); String name = Console. readLine (); try {wfobj. write (name);} catch (System. net. sockets. socketException e) {Console. writeLine (e. toString () ;}} Console. read ();}}}RemotingClient

Server code:

Using System; using System. collections. generic; using System. linq; using System. runtime. remoting; using System. runtime. remoting. channels; using System. runtime. remoting. channels. tcp; using System. text; namespace RemotingServer {class Program {static void Main (string [] args) {TcpChannel channel = new TcpChannel (8085); ChannelServices. registerChannel (channel, false); RemotingConfiguration. registerWellKnownServiceType (typeof (RemotingObjects. process), "RemotingWriteFileToLocalService", WellKnownObjectMode. singleCall); Console. writeLine ("Server: Press Enter key to exit"); Console. readLine ();}}}RemotingServer

Class library code:

Using System; using System. collections. generic; using System. IO; using System. linq; using System. text; namespace RemotingObjects {public interface WriteFileToLocal {void write (string content);} public class Process: externalbyrefobject, WriteFileToLocal {public Process () {Console. writeLine ("Write Starting... ");} /// <summary> /// write File /// </summary> /// <param name = "content"> write File content </param> public void write (string content) {using (StreamWriter sw = new StreamWriter (@ "D: \ remoting.txt", true, Encoding. default) {sw. write (content + "\ r \ n ");}}}}RemotingObjects

 

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.