コード例 #1
0
ファイル: TChannel.cs プロジェクト: adan830/Egametang
		public TChannel(TSocket socket, string host, int port, TService service): base(service)
		{
			this.socket = socket;
			this.service = service;
			this.parser = new PacketParser(this.recvBuffer);
			this.remoteAddress = host + ":" + port;
		}
コード例 #2
0
ファイル: TChannel.cs プロジェクト: adan830/Egametang
		public TChannel(TSocket socket, TService service): base(service)
		{
			this.isConnected = true;
			this.socket = socket;
			this.service = service;
			this.parser = new PacketParser(this.recvBuffer);
			this.remoteAddress = this.socket.RemoteAddress;
			this.StartRecv();
		}
コード例 #3
0
ファイル: TService.cs プロジェクト: adan830/Egametang
		private void Dispose(bool disposing)
		{
			if (this.acceptor == null)
			{
				return;
			}

			if (disposing)
			{
				foreach (ObjectId id in this.idChannels.Keys.ToArray())
				{
					TChannel channel = this.idChannels[id];
					channel.Dispose();
				}
				this.acceptor.Dispose();
			}

			this.acceptor = null;
		}
コード例 #4
0
ファイル: TChannel.cs プロジェクト: adan830/Egametang
		private void Dispose(bool disposing)
		{
			if (this.socket == null)
			{
				return;
			}

			this.onDispose(this);

			if (disposing)
			{
				// 释放托管的资源
				this.socket.Dispose();
			}

			// 释放非托管资源
			this.service.Remove(this);
			this.socket = null;
		}
コード例 #5
0
ファイル: TSocket.cs プロジェクト: adan830/Egametang
		public Task<bool> AcceptAsync(TSocket accpetSocket)
		{
			var tcs = new TaskCompletionSource<bool>();
			this.innArgs.UserToken = tcs;
			this.innArgs.AcceptSocket = accpetSocket.socket;
			if (!this.socket.AcceptAsync(this.innArgs))
			{
				OnAcceptComplete(this.innArgs);
			}
			return tcs.Task;
		}
コード例 #6
0
ファイル: TService.cs プロジェクト: rvpoochen/Egametang
 /// <summary>
 /// 即可做client也可做server
 /// </summary>
 /// <param name="host"></param>
 /// <param name="port"></param>
 public TService(string host, int port)
 {
     this.acceptor = new TSocket(this.poller);
     this.acceptor.Bind(host, port);
     this.acceptor.Listen(100);
 }
コード例 #7
0
ファイル: TService.cs プロジェクト: adan830/Egametang
		public async Task<AChannel> GetChannel()
		{
			if (this.acceptor == null)
			{
				throw new Exception("service construct must use host and port param");
			}
			TSocket socket = new TSocket(this.poller);
			await this.acceptor.AcceptAsync(socket);
			TChannel channel = new TChannel(socket, this);
			this.channels[channel.RemoteAddress] = channel;
			this.idChannels[channel.Id] = channel;
			return channel;
		}
コード例 #8
0
ファイル: TService.cs プロジェクト: adan830/Egametang
		/// <summary>
		/// 即可做client也可做server
		/// </summary>
		/// <param name="host"></param>
		/// <param name="port"></param>
		public TService(string host, int port)
		{
			this.acceptor = new TSocket(this.poller);
			this.acceptor.Bind(host, port);
			this.acceptor.Listen(100);
		}
コード例 #9
0
ファイル: TService.cs プロジェクト: adan830/Egametang
		public AChannel GetChannel(string host, int port)
		{
			TChannel channel = null;
			if (this.channels.TryGetValue(host + ":" + port, out channel))
			{
				return channel;
			}

			TSocket newSocket = new TSocket(this.poller);
			channel = new TChannel(newSocket, host, port, this);
			this.channels[channel.RemoteAddress] = channel;
			this.idChannels[channel.Id] = channel;
			this.SocketConnectAsync(channel);
			return channel;
		}