Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

.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.
reachability_demo.zip
reachability_demo
demo
Client
App.ico
bin
Debug
Client.csproj.user
KnownObjects
App.ico
KnownObjects.csproj.user
Server
App.ico
bin
Debug
Server.csproj.user
Reachability.csproj.user
reachability_src.zip
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

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.
 

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 21 Jun 2003
Article Copyright 2003 by zhi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid