Click here to Skip to main content
15,885,244 members
Articles / Programming Languages / C#

.NET Remoting Sample

Rate me:
Please Sign up or sign in to vote.
4.52/5 (50 votes)
14 Apr 20052 min read 246.1K   31.4K   138  
Shows how to use .NET Remoting for beginners.
using System;

namespace Remote
{
	[Serializable]
	public struct kAction
	{
		public string   s_Command;   // the text to be sent by master
		public string   s_Computer;  // Computer name of the sender (=slave)
		
		// to transfer more data expand here...
	};

	[Serializable]
	public struct kResponse
	{
		public string    s_Result;   // the response text sent by slave
		
		// to transfer more data expand here...
	};

	public class cTransfer : MarshalByRefObject
	{
		public delegate kResponse      del_SlaveCall(kAction k_Action);
		public event    del_SlaveCall  ev_SlaveCall;

		// Default public no argument constructor
		public cTransfer() 
		{
		}

		public kResponse CallSlave(kAction k_Action)
		{
			return ev_SlaveCall(k_Action);			
		}

		/// <summary>
		/// This override is EXTREMELY important
		/// If it is missing the garbage collector of the Slave will delete the cTransfer object
		/// after 5 minutes and the event will be lost, so further calls to the slave will return
		/// "Server encountered an internal error" (a very helpful Mircrosoft error message!)
		/// This function sets the livetime to infinite
		/// See http://www.thinktecture.com/Resources/RemotingFAQ/SINGLETON_IS_DYING.html
		/// </summary>
		public override Object InitializeLifetimeService()
		{
			return null;
		}
	}
}

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions