Giter Site home page Giter Site logo

grpcwpfsample's Introduction

Overview

Chat server-client applications as a sample implementation using gRPC for .NET (Grpc.AspNetCore/Grpc.Net.Client) and gRPC for C# (Grpc.Core).

Client

Project Type Target Used Package
GrpcChatSample.Client.ConsoleApp Console app .NET 6.0 Grpc.Core
GrpcChatSample.Client.Wpf WPF app .NET Framework 4.8 Grpc.Core
GrpcChatSample2.Client.ConsoleApp Console app .NET 6.0 Grpc.Net.Client
GrpcChatSample2.Client.Wpf WPF app .NET 6.0 Grpc.Net.Client

Server

Project Type Target Used Package
GrpcChatSample.Server.ConsoleApp Console app .NET 6.0 Grpc.Core
GrpcChatSample.Server.Wpf WPF app .NET Framework 4.8 Grpc.Core
GrpcChatSample2.Server.ConsoleApp Console app .NET 6.0 Grpc.AspNetCore
GrpcChatSample2.Server.Wpf WPF app .NET 6.0 Grpc.AspNetCore
  • These projects are not made from ASP.NET Core gRPC service project template, but adding gRPC service/client on console/WPF app project.
  • .NET Framework apps are supported by Grpc.Core.
  • ASP.NET Core apps are supported by both, but Grpc.AspNetCore/Grpc.Net.Client is recommended.
  • See https://grpc.io/blog/grpc-csharp-future/
  • You cannot put proto file in WPF project. See grpc/grpc#20402

Implements

  • Simple RPC: Client registers a message to server.
  • Server-side streaming RPC: Server streams messages to clients.
  • Interceptors: Client puts its ID for each calls. Server checks client IP address and ID for each calls.
  • Request Header R/W: Client puts its ID on request header (metadata) of the call.

Read the official information

RPC Service Definition (chat.proto)

service Chat {
  rpc Write(ChatLog) returns (google.protobuf.Empty) {}
  rpc Subscribe(google.protobuf.Empty) returns (stream ChatLog) {}
}

Architecture

GrpcChatSample_archtecture

DB is not implemented but on-memory List is used as a placeholder.

How to Run

  1. Start a server.
  2. Start client(s). You can start multiple clients.
    • For the console app, write a name and hit enter key first.
  3. On client, write a message and hit enter key.
  4. Your message will be registered on server, and you can see it on the client.

How to Enable SSL

grpc-dotnet

See these classes. Enable listenOptions.UseHttps() of server and locate .pfx file. Set var https = true of client.

GrpcCore

See these classes. Locate required files and then change var secure = true; to enable SSL.

File Name Description
localhost_server.crt Server's certificate
localhost_serverkey.pem Private key of the server's certificate
localhost_client.crt Client's certificate (optional)
localhost_clientkey.pem Private key of the client's certificate (optional)
  • All these files have to be PEM format without encryption.
  • The server has to have the client's certificate or its CA certificate and vice versa. Here you can find an idea about this.
  • The sample implementation includes client authentication as well. You can disable it then you don't need client's certificate and its private key.

Remarks

  • You have to set "localhost" as Common Name (CN) of the certificate for your test on localhost.
  • XCA is the one of the easy way to create the these files.

grpcwpfsample's People

Contributors

cactuaroid avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.