Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Build distribution applications by remoting(TCP/HTTP)

0.00/5 (No votes)
23 Mar 2008 3  
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(" 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 <code> 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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here