internal async Task ConnectAsync(IPEndPoint endpoint) { thread = new UvThread(); client = new UvTcpClient(thread, endpoint); connection = await client.ConnectAsync(); ReadLoop(); // will hand over to libuv thread }
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()); }
private static async Task RunHttpClient(IPAddress ip, int port) { var client = new UvTcpClient(ip, port); var consoleOutput = client.ChannelFactory.MakeWriteableChannel(Console.OpenStandardOutput()); var connection = await client.ConnectAsync(); // This is on a libuv thread while (true) { var buffer = connection.Input.Alloc(); WritableBufferExtensions.WriteAsciiString(ref buffer, "GET / HTTP/1.1"); WritableBufferExtensions.WriteAsciiString(ref buffer, "\r\n\r\n"); await connection.Input.WriteAsync(buffer); // Write the client output to the console await CopyCompletedAsync(connection.Output, consoleOutput); } }
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 static async Task RunRawHttpClient(IPAddress ip, int port) { var thread = new UvThread(); var client = new UvTcpClient(thread, new IPEndPoint(ip, port)); var consoleOutput = thread.ChannelFactory.MakeWriteableChannel(Console.OpenStandardOutput()); var connection = await client.ConnectAsync(); while (true) { var buffer = connection.Input.Alloc(); WritableBufferExtensions.WriteAsciiString(ref buffer, "GET / HTTP/1.1"); WritableBufferExtensions.WriteAsciiString(ref buffer, "\r\n\r\n"); await buffer.FlushAsync(); // Write the client output to the console await CopyCompletedAsync(connection.Output, consoleOutput); await Task.Delay(1000); } }
public static async Task Run() { var thread = new UvThread(); var client = new UvTcpClient(thread, new IPEndPoint(IPAddress.Loopback, 5000)); var consoleOutput = thread.ChannelFactory.MakeWriteableChannel(Console.OpenStandardOutput()); var connection = await client.ConnectAsync(); while (true) { var buffer = connection.Output.Alloc(); buffer.WriteAsciiString("GET / HTTP/1.1"); buffer.WriteAsciiString("\r\n\r\n"); await buffer.FlushAsync(); // Write the client output to the console await CopyCompletedAsync(connection.Input, consoleOutput); await Task.Delay(1000); } }
protected override async Task <IPipeConnection> GetConnection() { return(await client.ConnectAsync()); }