Click here to Skip to main content
Click here to Skip to main content

Build distribution applications by remoting(TCP/HTTP)

, 22 Mar 2008
Rate this:
Please Sign up or sign in to vote.
In this sample describes how to build a distribution application on remoting by Tcp protocol.

Introduction

In this sample describes how to build a distribution application on remoting by Tcp protocol.

Background

(Optional) Is there any background to this article that may be useful such as an introduction to the basic ideas presented?

Using the code

A brief description of how to use the article or code. The class names, the methods and properties, any tricks or tips.

Blocks of code should be set as style "Formatted" like this:

Server

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace www.treaple.com
{
        public class HelloServer 
        {

                public static void Main(string [] args) 
                {
            TcpServerChannel channel = new TcpServerChannel(8085);
                        //TcpChannel chan = new TcpChannel(8085);
                        ChannelServices.RegisterChannel(channel);
                        RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello),"Hi",WellKnownObjectMode.SingleCall);
                        System.Console.WriteLine("<enter> to quite...");
                        System.Console.ReadLine();

                }
        }
}

Client

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace www.treaple.com 
{
        public class Client
        {
                [STAThread]
                public static void Main(string [] args)
                {
                        //TcpChannel chan = new TcpChannel();
                        ChannelServices.RegisterChannel(new TcpClientChannel());
                        Hello obj = (Hello)Activator.GetObject(typeof(Hello),"tcp://localhost:8085/Hi");
                        if (obj == null) System.Console.WriteLine("Could not find machine!");
                        else Console.WriteLine(obj.Greeting("John"));
                        //else Console.WriteLine(obj.HelloMethod("John"));

                } 
        }
}

interface:

using System;

namespace www.treaple.com{
    public interface IHello {
        String HelloMethod(String name);
    }

    public class HelloServer : MarshalByRefObject, IHello {
        public HelloServer() {
            Console.WriteLine("HelloServer actived");
        }

        public String HelloMethod(String name) {
            Console.WriteLine("Hello.HelloMethod : {0}", name);
            return "hello," + name;
        }
    }
}

		

Remember to set the Language of your code snippet using the Language dropdown.

Use the "var" button to to wrap Variable or class names in &lt;code&gt; tags like this.

Points of Interest

Did you learn anything interesting/fun/annoying while writing the code? Did you do anything particularly clever or wild or zany?

History

If you have any questions about this sample,please visit http://www.treaple.com/bbs/thread-27-1-1.html or send email to me.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

John.Jiang
Software Developer (Senior) www.treaple.com
China China
Treaple offshore outsourcing software services providing mobile(Pocket pc,smartphone and wince.net) software,mobile GIS(Mobile map),Desktop GIS(Desktop map), GPS,GSM Locating Services,Voip,Multimedia(Audio,Video) and web design offshore outsourcing software development services.We have developed lots of projects on Microsoft Poccket pc 5.0/6.0,smartphone 5.0/6.0 and Microsoft windows and got strong background in Microsoft MapPoint, ESRI ArcGIS, Map info,Google map etc
Our website below: http://www.treaple.com

Comments and Discussions

 
QuestionHi John.Jiang I read your article after I have got a question. PinmemberParkJaeHyuk3-Nov-08 13:03 
AnswerRe: Hi John.Jiang I read your article after I have got a question. PinmemberJohn.Jiang3-Nov-08 18:34 
GeneralRe: Hi John.Jiang I read your article after I have got a question. Pinmembermbaocha6-May-09 12:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 23 Mar 2008
Article Copyright 2008 by John.Jiang
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid