Demonstration of the gRPC protocol with a Dart server and a Flutter client.
gRPC is a cross-platform open source high performance Remote Procedure Call (RPC) framework which sends structured binary data over HTTP/2 instead of plaintext JSON, uses Protocol Buffers for model development and provides features such as authentication, bidirectional streaming and flow control, blocking or nonblocking bindings, and cancellation and timeouts.
Protocol Buffers allows us to define our data structures. After their definition we should use protobuf compiler to generate source code from these data structures. In order to generate the gRPC client and server interfaces from our .proto service definition run generate.sh
To start the server:
dart bin/grpc_dart_server.dart
First, you must find out the IPv4 address of your computer.
Open terminal and use
ipconfig
After running this command, you'll need to copy the IPv4 address to grpc_flutter_client/lib/data/utils/constants/connectivity_constants.dart. Don`t change port.
To start the client:
cd grpc_flutter_client && flutter run
In order to run on a real device, you must use ngrok. Ngrok is a globally distributed reverse proxy fronting your web services running in any cloud or private network, or your machine (enough a free ngrok account).
ngrok tcp 50001
Now you need to copy the Forwarding
address (both host and port) to grpc_flutter_client/lib/data/utils/constants/connectivity_constants.dart.