コード例 #1
0
		private void DisplayTcpServerInfo(TcpServer server, ITerminal output)
		{
			this.DisplayListenerInfo(server, output);

			if(!server.IsListening)
				return;

			output.WriteLine();
			output.Write(TerminalColor.DarkMagenta, "ID\t");
			output.Write(TerminalColor.DarkMagenta, ResourceUtility.GetString("${LastReceivedTime}") + "\t\t");
			output.Write(TerminalColor.DarkMagenta, ResourceUtility.GetString("${LastSendTime}") + "\t\t");
			output.Write(TerminalColor.DarkMagenta, ResourceUtility.GetString("${LocalEndPoint}") + "\t\t");
			output.WriteLine(TerminalColor.DarkMagenta, ResourceUtility.GetString("${RemoteEndPoint}") + "\t");

			var channels = server.ChannelManager.GetActivedChannels();

			foreach(TcpServerChannel channel in channels)
			{
				if(channel == this.Channel)
					output.Write(TerminalColor.Magenta, "* ");

				output.WriteLine(
					"{0}\t{1:yyyy-MM-dd HH:mm:ss}\t{2:yyyy-MM-dd HH:mm:ss}\t{3}\t\t{4}",
					channel.ChannelId,
					channel.LastReceivedTime,
					channel.LastSendTime,
					channel.LocalEndPoint,
					channel.RemoteEndPoint);
			}

			output.WriteLine();
		}
コード例 #2
0
		public TcpServerChannelManager(TcpServer server, IPacketizerFactory packetizerFactory)
		{
			if(server == null)
				throw new ArgumentNullException("server");

			//保存当前通道管理器所属的服务器对象
			_server = server;
			//保存当前通道管理器的协议解析器工厂
			_packetizerFactory = packetizerFactory;

			//创建活动通道池
			_activedChannels = new ConcurrentDictionary<int, TcpServerChannel>();

			//挂载服务器的接受事件
			_server.Accepted += new EventHandler<ChannelEventArgs>(Server_Accepted);

			//创建通道对象池
			_channelPool = new Collections.ObjectPool<TcpServerChannel>(() =>
			{
				var channel = this.CreateChannel(System.Threading.Interlocked.Increment(ref _channelId));

				if(channel != null && channel.Packetizer == null && _packetizerFactory != null)
				{
					channel.Packetizer = _packetizerFactory.GetPacketizer(channel);
				}

				return channel;
			}, null);
		}
コード例 #3
0
 public TcpServerChannelManager(TcpServer server) : this(server, null)
 {
 }
コード例 #4
0
		public TcpServerChannelManager(TcpServer server) : this(server, null)
		{
		}