helloserver.cs

来自「Professional C# 2nd Edition」· CS 代码 · 共 57 行

CS
57
字号
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;

namespace Wrox.ProfessionalCSharp
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class HelloServer
	{
		protected static void ShowChannelProperties(IChannelReceiver channel)
		{
			Console.WriteLine("Name: " + channel.ChannelName);
			Console.WriteLine("Priority: " + channel.ChannelPriority);

			if (channel is HttpChannel)
			{
				HttpChannel httpChannel = channel as HttpChannel;
				Console.WriteLine("Scheme: " + httpChannel.ChannelScheme);
			}

			ChannelDataStore data = (ChannelDataStore)channel.ChannelData;
			foreach (string uri in data.ChannelUris)
			{
				Console.WriteLine("URI: " + uri);
			}
			Console.WriteLine();
		}

		public static void Main(string[] args)
		{
			TcpServerChannel tcpChannel = new TcpServerChannel(8086);

			ShowChannelProperties(tcpChannel);

			HttpServerChannel httpChannel = new HttpServerChannel(8085);

			ShowChannelProperties(httpChannel);

			ChannelServices.RegisterChannel(tcpChannel);
			ChannelServices.RegisterChannel(httpChannel);

			Console.WriteLine(RemotingConfiguration.ApplicationName);
			RemotingConfiguration.ApplicationName = "HelloServer";

			RemotingConfiguration.RegisterActivatedServiceType(
				typeof(Hello));

			System.Console.WriteLine("hit to exit");
			System.Console.ReadLine();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?