public static async Task Run() { var thread = new UvThread(); var client = new UvTcpClient(thread, new IPEndPoint(IPAddress.Loopback, 5000)); var consoleOutput = thread.PipelineFactory.CreateWriter(Console.OpenStandardOutput()); var connection = await client.ConnectAsync(); while (true) { var buffer = connection.Output.Alloc(); buffer.Append("GET / HTTP/1.1", TextEncoding.Utf8); buffer.Append("\r\n\r\n", TextEncoding.Utf8); await buffer.FlushAsync(); // Write the client output to the console await CopyCompletedAsync(connection.Input, consoleOutput); await Task.Delay(1000); } }
private async Task<UvTcpConnection> ConnectAsync(HttpRequestMessage request) { var addresses = await Dns.GetHostAddressesAsync(request.RequestUri.Host); var port = request.RequestUri.Port; var address = addresses.First(a => a.AddressFamily == AddressFamily.InterNetwork); var connection = new UvTcpClient(_thread, new IPEndPoint(address, port)); return await connection.ConnectAsync(); }