Click here to Skip to main content
12,511,920 members (44,045 online)
Click here to Skip to main content

Stats

85.6K views
1.6K downloads
27 bookmarked
Posted

.NET Remoting Message Redirection Channel Sinks

, 20 Jun 2003
An upper logic layer transparent way to redirect .NET remoting calls, enabling exposure of .NET remoting services behind firewall/NAT, to anywhere.
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Services;
using System.Runtime.Remoting.Messaging;
using System.Collections;

namespace KnownObjects
{
	/// <summary>
	/// Message receiver.
	/// </summary>
	public interface IChatClient
	{
		/// <summary>
		/// Receives message.
		/// One way attribute make this call async.
		/// </summary>
		/// <param name="message"></param>
		[OneWay]
		void ReceiveMessage(string message);

		bool Function();
	}

	public class ChatRoom : MarshalByRefObject
	{
		public int SendMessage(string message)
		{
			lock(arrayOfClients)
			{
				Console.WriteLine("\"{0}\" message will be sent to all clients.", message);
				//Console.WriteLine(MessageManager.GetMessageSender(GenuineUtility.FetchCurrentRemoteUri()).GetRemoteEndPoint().ToString());
				if (message != null)
				{
					foreach (IChatClient iChatClient in arrayOfClients)
						iChatClient.ReceiveMessage(message);
				}

				return arrayOfClients.Count;
			}
		}
		ArrayList arrayOfClients = new ArrayList();		
		
		public void AttachClient(IChatClient iChatClient)
		{
			if (iChatClient == null)
				return ;
			
			//ObjRef or = RemotingServices.Marshal(iChatClient as MarshalByRefObject);
			lock(arrayOfClients)
			{
				arrayOfClients.Add(iChatClient);
			}
		}
		public void DetachClient(IChatClient iChatClient)
		{
			if (iChatClient == null)
				return ;

			lock(arrayOfClients)
			{
				arrayOfClients.Remove(iChatClient);
			}
		}

	}
}

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

Share

About the Author

zhi
Researcher
United States United States
My name is Zhiheng Cao. I major in Eletronics Engineering, in University of Tokyo. I do part time jobs of computer programming and teaching high school students English and Mathematics.

CodeProject provided me with valuable information for my programming job many times in the past. I hope I can do my part by providing goodies I have.


You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160929.1 | Last Updated 21 Jun 2003
Article Copyright 2003 by zhi
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid