Beispiel #1
0
        public void Configure(IApplicationBuilder app)
        {
            //Make sure that the grpc-server is run
            app.Run(async context =>
            {
                //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:5500"); //check the values at /server project
                var client  = new Billboard.Board.BoardClient(channel);
                var request = new Billboard.MessageRequest();
                request.Capabilities.Add("fly", new Billboard.MessageRequest.Types.SuperPower {
                    Name = "Flying", Level = 1
                });
                request.Capabilities.Add("inv", new Billboard.MessageRequest.Types.SuperPower {
                    Name = "Invisibility", Level = 10
                });
                request.Capabilities.Add("spe", new Billboard.MessageRequest.Types.SuperPower {
                    Name = "Speed", Level = 5
                });

                var reply = await client.ShowMessageAsync(request);

                var displayDate = new DateTime(reply.ReceivedTime);
                await context.Response.WriteAsync($"We sent a message to a gRPC server and  received  the following reply \n'\n{reply.Message}' \non {displayDate} ");
            });
        }
Beispiel #2
0
        public void Configure(IApplicationBuilder app)
        {
            //Make sure that the grpc-server is run
            app.Run(async context =>
            {
                //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:5500");
                var client  = new Billboard.Board.BoardClient(channel);
                var result  = client.ShowMessage(new Billboard.MessageRequest
                {
                    Name = "Johny"
                });

                context.Response.Headers["Content-Type"] = "text/event-stream";

                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);
                    await context.Response.WriteAsync($"Received \"{reply.Message}\" on {displayDate.ToLongTimeString()} \n");
                    await context.Response.Body.FlushAsync();
                }
            });
        }
Beispiel #3
0
        public void Configure(IApplicationBuilder app)
        {
            //Make sure that the grpc-server is run
            app.Run(async context =>
            {
                //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.
                var handler = new GrpcWebHandler(GrpcWebMode.GrpcWebText, new HttpClientHandler());
                var channel = GrpcChannel.ForAddress("http://localhost:5500", new GrpcChannelOptions
                {
                    HttpClient = new HttpClient(handler)
                });

                var client = new Billboard.Board.BoardClient(channel);

                var reply = await client.ShowMessageAsync(new Billboard.MessageRequest
                {
                    Message = "Good morning people of the world",
                    Sender  = "Dody Gunawinata"
                });

                Console.WriteLine("Connecting");

                var displayDate = new DateTime(reply.DisplayTime);
                await context.Response.WriteAsync($"This server sends a gRPC request to a server and get the following result: Received message on {displayDate} from {reply.ReceiveFrom}");
            });
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseStaticFiles();

            //Make sure that the grpc-server is run
            app.Run(async context =>
            {
                //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:5500"); //check the values at /server project
                var client  = new Billboard.Board.BoardClient(channel);
                var result  = client.ShowMessage(new Google.Protobuf.WellKnownTypes.Empty());

                context.Response.Headers["Content-Type"] = "text/html";

                await context.Response.WriteAsync("<html><body><h1>Kitty Streaming</h1>");

                using var tokenSource   = new CancellationTokenSource();
                CancellationToken token = tokenSource.Token;

                var streamReader = result.ResponseStream;

                //get metdata
                string path = null;
                await streamReader.MoveNext(token);
                var initial = streamReader.Current;
                if (initial.ImageCase == Billboard.MessageReply.ImageOneofCase.MetaData)
                {
                    path = Path.Combine(env.WebRootPath, initial.MetaData.FileName);
                }

                if (path == null)
                {
                    throw new ApplicationException("Metadata is missing from the server");
                }

                using FileStream file = new FileStream(path, FileMode.Create);

                int position = 0;
                await foreach (var data in streamReader.ReadAllAsync(token))
                {
                    var chunk = data.Chunk;
                    await file.WriteAsync(chunk.Data.ToByteArray(), 0, chunk.Length);
                    position += chunk.Length;
                    await context.Response.WriteAsync(position + " ");
                }

                file.Close();

                await context.Response.WriteAsync($"<img src=\"{initial.MetaData.FileName}\"/>");

                await context.Response.WriteAsync("</body></html>");
            });
        }
        public void Configure(IApplicationBuilder app)
        {
            //Make sure that the grpc-server is run
            app.Run(async context =>
            {
                //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:5500"); //check the values at /server project
                var client  = new Billboard.Board.BoardClient(channel);

                context.Response.Headers["Content-Type"] = "text/event-stream";

                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 Billboard.MessageRequest
                    {
                        FortuneCookie = f
                    });

                    await context.Response.WriteAsync($"Sending \"{f}\" \n");
                    await context.Response.Body.FlushAsync();

                    await Task.Delay(1000); //1 second
                }

                await stream.RequestStream.CompleteAsync();

                var response = await stream.ResponseAsync;

                await context.Response.WriteAsync("\n\n");

                foreach (var r in response.Fortunes)
                {
                    await context.Response.WriteAsync($"Reply \"{r.Message}\". Original cookied received on {new DateTime(r.ReceivedTime)}. \n");
                }
            });
        }
Beispiel #6
0
        public void Configure(IApplicationBuilder app)
        {
            //Make sure that the grpc-server is run
            app.Run(async context =>
            {
                //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:5500"); //check the values at /server project
                var client  = new Billboard.Board.BoardClient(channel);

                context.Response.Headers["Content-Type"] = "text/event-stream";

                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 Billboard.MessageRequest {
                            Ping = "Ping", DelayTime = delay
                        });
                        inc++;
                        await context.Response.WriteAsync($"Send ping on {DateTimeOffset.UtcNow} \n");
                        response = await stream.ResponseStream.MoveNext(token);
                        if (response)
                        {
                            var result = stream.ResponseStream.Current;
                            await context.Response.WriteAsync($"Receive {result.Pong} on {DateTimeOffset.UtcNow} \n\n");
                        }
                    }
                    catch (System.OverflowException)
                    {
                        inc = 1;
                    }
                }while (response);
            });
        }
        public void Configure(IApplicationBuilder app)
        {
            //Make sure that the grpc-server is run
            app.Run(async context =>
            {
                //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:5500");
                var client  = new Billboard.Board.BoardClient(channel);
                var reply   = await client.ShowMessageAsync(new Billboard.MessageRequest
                {
                    Message = "Good morning people of the world",
                    Sender  = "Dody Gunawinata"
                });

                var displayDate = new DateTime(reply.DisplayTime);
                await context.Response.WriteAsync($"This server sends a gRPC request to a server and get the following result: Received message on {displayDate} from {reply.ReceiveFrom}");
            });
        }
Beispiel #8
0
        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            builder.RootComponents.Add <App>("app");

            builder.Services.AddSingleton(x =>
            {
                var handler = new GrpcWebHandler(GrpcWebMode.GrpcWebText, new HttpClientHandler());
                var channel = GrpcChannel.ForAddress("http://localhost:5500", new GrpcChannelOptions
                {
                    HttpClient = new HttpClient(handler)
                });

                var client = new Billboard.Board.BoardClient(channel);
                return(client);
            });

            await builder.Build().RunAsync();
        }
        public void Configure(IApplicationBuilder app)
        {
            //Make sure that the grpc-server is run
            app.Run(async context =>
            {
                //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:5500"); //check the values at /server project
                var client  = new Billboard.Board.BoardClient(channel);
                var reply   = await client.ShowMessageAsync(new Billboard.MessageRequest
                {
                    Message = "Hello World",
                    Sender  = "Dody Gunawinata",
                    Type    = Billboard.MessageRequest.Types.MessageType.LongForm
                });

                var displayDate = new DateTime(reply.ReceivedTime);
                await context.Response.WriteAsync($"We sent a message to a gRPC server and  received  the following reply '{reply.Message}' on {displayDate} ");
            });
        }