Click here to Skip to main content
12,353,602 members (66,973 online)
Click here to Skip to main content

Stats

84.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.Threading;

using KnownObjects;

namespace Client
{
	/// <summary>
	/// ChatClient demostrates simple client application.
	/// </summary>
	class ChatClient : MarshalByRefObject, IChatClient
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			RemotingConfiguration.Configure("Client.exe.config");
					
			for(;;)
			{
				try
				{
					Reachability.ServerSinkProvider.StartWaitRedirectedMsg();

					Console.WriteLine(".NET Remoting has been configured from the Client.exe.config file.");
					ChatRoom chatRoom = new ChatRoom();

					ChatClient c = new ChatClient();
					ObjRef or = RemotingServices.Marshal(c as MarshalByRefObject);
					chatRoom.AttachClient(c);

					for(;;)
					{
						Console.WriteLine("Enter a message to send or an empty string to exit.");

						string str = Console.ReadLine();
						
						if (str.Length <= 0)
							return ;

						int numberOfReceivers = chatRoom.SendMessage(str);
						Console.WriteLine("Message \"{0}\" has been sent. {1} receivers registered at the server.", str, numberOfReceivers);
					}
				}
				catch(Exception ex)
				{
					Console.WriteLine(ex.ToString());
				}
				
				Console.WriteLine("Next attempt to connect to the server will be in 5 seconds.");
				Console.ReadLine();
			}
		}

		/// <summary>
		/// Message receiver.
		/// It receives messages async and writes them separately from the main thread.
		/// But it does not matter for console application.
		/// </summary>
		/// <param name="message">The message.</param>
        public void ReceiveMessage(string message)
		{
			Console.WriteLine("Message \"{0}\" has been received from the server.", message);
		}
		public bool Function()
		{
			Console.WriteLine("Function");
			return true;
		}
	}
}

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...

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