Click here to Skip to main content
15,892,737 members
Articles / Programming Languages / C#

Remote methods and events in C#

Rate me:
Please Sign up or sign in to vote.
3.91/5 (21 votes)
6 Sep 20033 min read 167K   2.3K   41  
An article on Remoting in C#
using System;
using mycomponent;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Server
{
	class Class1
	{
		
		static void Main(string[] args)
		{
			TcpChannel m_TcpChan = new TcpChannel(9999);
			ChannelServices.RegisterChannel(m_TcpChan);

			Type theType = new  ServerClass().GetType();  
					
			RemotingConfiguration.RegisterWellKnownServiceType(
				theType,
				"FirstRemote",
				WellKnownObjectMode.Singleton);
	
			System.Console.WriteLine("Press ENTER to quit");
			System.Console.ReadLine();
		}
	}

	public class ServerClass : AbstractServer
	{
		public override string myfunc(string what)
		{
			Console.WriteLine("in myfunc");
			FireNewBroadcastedMessageEvent("Event: " + what + " was said");
			return "Take " + what;
		}

		public event  myeventhandler myHandler;

		public override event myeventhandler myevent
		{
			add
			{
				Console.WriteLine("in event myevent + add");
							
				myHandler = value;
			}

			remove
			{
				Console.WriteLine("in event myevent + remove");
			}
		}

			protected void FireNewBroadcastedMessageEvent(string text)
			{
				Console.WriteLine("Broadcasting...");
				myHandler("hai");
			}

			
		}

	}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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


Written By
Web Developer
India India
I am Sanjeev Krishnan.

Comments and Discussions