static async Task ConnectAsync(string target, string clientName) { var channel = new Channel(target, ChannelCredentials.Insecure); await channel.ConnectAsync(); Console.WriteLine(clientName + " Connected."); var client = new Greeter.GreeterClient(channel); using (var server = client.Bidirectional( headers: new Metadata { new Metadata.Entry("name", clientName) })) { var responseReaderTask = Task.Run(async() => { while (await server.ResponseStream.MoveNext(CancellationToken.None)) { SabberResponse response = server.ResponseStream.Current; Console.WriteLine("Response received: " + response.Message);; } }); await server.RequestStream.WriteAsync(new SabberRequest { Type = SabberRequest.Types.Type.Test1 }); await server.RequestStream.CompleteAsync(); await responseReaderTask; Console.WriteLine("Client " + clientName + " is disconnected."); } }