static async Task Main(string[] args) { //We need this switch because we are connecting to an unsecure server. If the server runs on SSL, there's no need for this switch. AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); var channel = GrpcChannel.ForAddress("http://localhost:5000"); var client = new Board.BoardClient(channel); var request = new MessageRequest(); request.Capabilities.Add(new MessageRequest.Types.SuperPower { Name = "Flying", Level = 1 }); request.Capabilities.Add(new MessageRequest.Types.SuperPower { Name = "Invisibility", Level = 10 }); request.Capabilities.Add(new MessageRequest.Types.SuperPower { Name = "Speed", Level = 5 }); var reply = await client.ShowMessageAsync(request); var displayDate = new DateTime(reply.ReceivedTime); Console.WriteLine( $"We sent a message to a gRPC server and received the following reply \n'\n{reply.Message}' \non {displayDate} "); Console.WriteLine("End"); Console.Read(); }
static async Task Main(string[] args) { AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); var channel = GrpcChannel.ForAddress("http://localhost:5000"); var client = new Board.BoardClient(channel); using var tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; using var stream = client.ShowMessage(cancellationToken: token); bool response = true; int inc = 1; do { try { var delay = checked (1000 * inc); await stream.RequestStream.WriteAsync(new MessageRequest { Ping = "Ping", DelayTime = delay }); inc++; Console.WriteLine($"Send ping on {DateTimeOffset.UtcNow} \n"); response = await stream.ResponseStream.MoveNext(token); if (response) { var result = stream.ResponseStream.Current; Console.WriteLine($"Receive {result.Pong} on {DateTimeOffset.UtcNow} \n\n"); } } catch (OverflowException) { inc = 1; } } while (response); Console.WriteLine("End"); Console.ReadLine(); }
static async Task Main(string[] args) { //We need this switch because we are connecting to an unsecure server. If the server runs on SSL, there's no need for this switch. AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); var channel = GrpcChannel.ForAddress("http://localhost:5000"); var client = new Board.BoardClient(channel); var reply = await client.ShowMessageAsync(new MessageRequest { Message = "Good morning people of the world", Sender = "Dody Gunawinata" }); var displayDate = new DateTime(reply.DisplayTime); Console.WriteLine($"This server sends a gRPC request to a server and get the following result: Received message on {displayDate} from {reply.ReceiveFrom}"); Console.ReadLine(); }
static async Task Main(string[] args) { AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); var channel = GrpcChannel.ForAddress("http://localhost:5000"); var client = new Board.BoardClient(channel); using var tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; using var stream = client.ShowMessage(cancellationToken: token); foreach (var f in Fortunes) { if (token.IsCancellationRequested) { break; } await stream.RequestStream.WriteAsync(new MessageRequest { FortuneCookie = f }); Console.WriteLine($"Sending \"{f}\" \n"); await Task.Delay(1000, token); } await stream.RequestStream.CompleteAsync(); var response = await stream.ResponseAsync; Console.WriteLine($"\n\n"); foreach (var r in response.Fortunes) { Console.WriteLine( $"Reply \"{r.Message}\". Original cookied received on {new DateTime(r.ReceivedTime)}. \n"); } Console.WriteLine("End"); Console.ReadLine(); }
static async Task Main(string[] args) { //We need this switch because we are connecting to an unsecure server. If the server runs on SSL, there's no need for this switch. AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); var channel = GrpcChannel.ForAddress("http://localhost:5000"); var client = new Board.BoardClient(channel); var reply = await client.ShowMessageAsync(new MessageRequest { Message = "Hello World", Sender = "Dody Gunawinata", Type = MessageRequest.Types.MessageType.LongForm }); var displayDate = new DateTime(reply.ReceivedTime); Console.WriteLine( $"We sent a message to a gRPC server and received the following reply '{reply.Message}' on {displayDate} "); Console.WriteLine("End"); Console.Read(); }
static async Task Main(string[] args) { //We need this switch because we are connecting to an unsecure server. If the server runs on SSL, there's no need for this switch. AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); var channel = GrpcChannel.ForAddress("http://localhost:5000"); var client = new Board.BoardClient(channel); var result = client.ShowMessage(new MessageRequest { Name = "Johny" }); using var tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; var streamReader = result.ResponseStream; await foreach (var reply in streamReader.ReadAllAsync(token)) { var displayDate = new DateTime(reply.DisplayTime); Console.WriteLine($"Received \"{reply.Message}\" on {displayDate.ToLongTimeString()} \n"); } Console.ReadLine(); }