Example #1
0
		async static public Task Create(Func<TcpSocket, Task> Server, Func<ushort, Task> Client)
		{
			var TestPort = TcpServer.GetAvailablePort();
			var TcpListener = new TcpServer(Port: TestPort, Bind: "127.0.0.1", CatchExceptions: false);
			TcpListener.HandleClient += async (TcpSocket) =>
			{
				await Server(TcpSocket);
				await TcpSocket.CloseAsync();
			};
			var ListeningTask = TcpListener.ListenAsync(1);
			{
				await Client(TestPort);
			}
			await ListeningTask;
		}
Example #2
0
		async public virtual Task ListenAsync(ushort Port = 80, string Host = "0.0.0.0")
		{
			this.Port = Port;
			this.Host = Host;
			this.TcpServer = new TcpServer(Port, Host);
			this.TcpServer.HandleClient += TcpServer_HandleClient;
			await TcpServer.ListenAsync();
			Console.WriteLine("End Http Server");
		}