### Navigate to Example Directory Source: https://grpc.io/docs/languages/dart/basics Change your current directory to the gRPC route guide example directory to begin. ```bash cd example/route_guide ``` -------------------------------- ### Navigate to Route Guide Example Directory Source: https://grpc.io/docs/languages/cpp/basics Change to the route guide example directory within the gRPC repository. This is a prerequisite for building and running the example. ```bash cd examples/cpp/route_guide ``` -------------------------------- ### Navigate to Objective-C Route Guide Example Source: https://grpc.io/docs/languages/objective-c/basics Change your current directory to the Objective-C route guide example within the cloned gRPC repository. ```bash cd examples/objective-c/route_guide ``` -------------------------------- ### Navigate to Example Directory Source: https://grpc.io/docs/languages/cpp/quickstart Change the current directory to the C++ helloworld example. ```bash cd examples/cpp/helloworld ``` -------------------------------- ### Download and Navigate Example Code Source: https://grpc.io/docs/languages/ruby/quickstart Clone the gRPC repository to obtain the example code and navigate to the Ruby 'hello, world' example directory. ```bash # Clone the repository to get the example code: git clone -b v1.81.0 --depth 1 --shallow-submodules https://github.com/grpc/grpc # Navigate to the "hello, world" Ruby example: cd grpc/examples/ruby ``` -------------------------------- ### Navigate to Example Directory Source: https://grpc.io/docs/languages/go/basics Change the current directory to the route_guide example within the cloned grpc-go repository. ```bash cd grpc-go/examples/route_guide ``` -------------------------------- ### Build Example (Windows) Source: https://grpc.io/docs/languages/cpp/quickstart Build the gRPC C++ helloworld example using cmake on Windows. ```bash mkdir "cmake\build" pushd "cmake\build" cmake -DCMAKE_INSTALL_PREFIX=%MY_INSTALL_DIR% ..\.. cmake --build . --config Release -j 4 popd ``` -------------------------------- ### Navigate to Android Examples Directory Source: https://grpc.io/docs/platforms/android/java/basics Change your current directory to the android examples within the cloned grpc-java repository. This is where the tutorial's example code resides. ```bash cd grpc-java/examples/android ``` -------------------------------- ### Run gRPC Server Source: https://grpc.io/docs/languages/node/quickstart Start the gRPC server from the example directory. Ensure you are in the `examples/helloworld/dynamic_codegen` directory before running this command. ```bash node greeter_server.js ``` -------------------------------- ### Navigate to Example Directory Source: https://grpc.io/docs/languages/go/quickstart Change the current directory to the helloworld example within the cloned grpc-go repository. ```bash cd grpc-go/examples/helloworld ``` -------------------------------- ### Navigate to Example Directory Source: https://grpc.io/docs/languages/dart/basics Change your current directory to the route_guide example within the cloned grpc-dart repository. ```bash cd grpc-dart/example/route_guide ``` -------------------------------- ### Run gRPC Server Source: https://grpc.io/docs/languages/java/quickstart Start the gRPC server from the examples directory. The server will listen on port 50051. ```bash ./build/install/examples/bin/hello-world-server INFO: Server started, listening on 50051 ``` -------------------------------- ### Install Ruby Dependencies Source: https://grpc.io/docs/languages/ruby/basics Install Bundler and then install all necessary gem dependencies for the gRPC examples. ```bash gem install bundler && bundle install ``` -------------------------------- ### Run Node.js Server Source: https://grpc.io/docs/languages/node/basics Starts the route guide server application. Ensure you provide the path to the database file. ```bash node ./routeguide/dynamic_codegen/route_guide_server.js --db_path=./routeguide/dynamic_codegen/route_guide_db.json ``` -------------------------------- ### Navigate to Examples Directory Source: https://grpc.io/docs/languages/java/quickstart Change your current directory to the examples folder within the cloned grpc-java repository. ```bash cd grpc-java/examples ``` -------------------------------- ### Build and Install gRPC Client for Android Source: https://grpc.io/docs/platforms/android/kotlin/quickstart Build the client application and install it on your Android device using Gradle. This command is run from the 'examples' directory. ```bash ./gradlew :android:installDebug ``` -------------------------------- ### Configure Build with CMake Source: https://grpc.io/docs/languages/cpp/basics Use CMake to configure the build for the gRPC route guide example. Ensure you specify the installation directory for gRPC. ```bash mkdir -p cmake/build cd cmake/build cmake -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR ../.. ``` -------------------------------- ### Navigate to Examples Directory Source: https://grpc.io/docs/languages/rust/quickstart Change the current directory to the examples folder within the cloned grpc-rust repository. ```bash cd grpc-rust/examples ``` -------------------------------- ### Run Node.js gRPC Server Source: https://grpc.io/docs/languages/php/basics Compile and run the Node.js gRPC server for the route guide example. This server is needed to test the PHP client. Ensure you have Node.js and npm installed. ```bash cd ../../node npm install cd dynamic_codegen/route_guide nodejs ./route_guide_server.js --db_path=route_guide_db.json ``` -------------------------------- ### Navigate to Examples Directory Source: https://grpc.io/docs/languages/node/basics Change the current directory to the examples folder within the cloned gRPC Node.js repository. ```bash cd examples ``` -------------------------------- ### Download Dependencies and Run Example Source: https://grpc.io/docs/languages/dart/quickstart Download package dependencies for the gRPC example and then run the server and client applications. ```bash dart pub get ``` ```bash dart bin/server.dart ``` ```bash dart bin/client.dart Greeter client received: Hello, world! ``` -------------------------------- ### Clone gRPC Dart Example Source: https://grpc.io/docs/languages/dart/quickstart Clone the gRPC Dart repository to access the example code. Navigate to the quick start example directory. ```bash git clone https://github.com/grpc/grpc-dart ``` ```bash cd grpc-dart/example/helloworld ``` -------------------------------- ### Build Example (Linux/macOS) Source: https://grpc.io/docs/languages/cpp/quickstart Build the gRPC C++ helloworld example using cmake on Linux or macOS. ```bash mkdir -p cmake/build pushd cmake/build cmake -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR ../.. make -j 4 popd ``` -------------------------------- ### Launch gRPC-Web Example Services Source: https://grpc.io/docs/platforms/web/quickstart Start the Node.js server, Envoy proxy, and client services in detached mode using Docker Compose. ```bash docker-compose up -d node-server envoy commonjs-client ``` -------------------------------- ### Navigate to PHP Examples Directory Source: https://grpc.io/docs/languages/php/quickstart Change the current directory to the PHP examples within the cloned gRPC repository. ```bash cd grpc/examples/php ``` -------------------------------- ### Compile the gRPC Server Source: https://grpc.io/docs/platforms/android/kotlin/quickstart Compile the server component of the gRPC example using Gradle. This command installs the necessary distribution for running the server. ```bash ./gradlew installDist ``` -------------------------------- ### RouteGuide Server Constructor and Start Source: https://grpc.io/docs/languages/java/basics Constructs and starts a gRPC server for the RouteGuide service. Requires port and feature data for initialization. ```java public RouteGuideServer(int port, URL featureFile) throws IOException { this(ServerBuilder.forPort(port), port, RouteGuideUtil.parseFeatures(featureFile)); } /** Create a RouteGuide server using serverBuilder as a base and features as data. */ public RouteGuideServer(ServerBuilder serverBuilder, int port, Collection features) { this.port = port; server = serverBuilder.addService(new RouteGuideService(features)) .build(); } ... public void start() throws IOException { server.start(); logger.info("Server started, listening on " + port); ... } ``` -------------------------------- ### Build and Install gRPC Source: https://grpc.io/docs/languages/objective-c/quickstart Compile and install the gRPC libraries and plugins on your system. This step is crucial for using gRPC in your projects. ```bash cd grpc make [sudo] make install ``` -------------------------------- ### Build and Install the Android Client Source: https://grpc.io/docs/platforms/android/java/quickstart Build the Android client application and install it on a device. This command navigates into the android/helloworld directory and then runs the Gradle installDebug task. ```bash (cd android/helloworld; ../../gradlew installDebug) ``` -------------------------------- ### Navigate to gRPC Kotlin Examples Directory Source: https://grpc.io/docs/languages/kotlin/basics Change the current directory to the examples folder within the cloned grpc-kotlin repository to access the tutorial's code. ```bash cd grpc-kotlin/examples ``` -------------------------------- ### Create and Start RPC with Call Options Source: https://grpc.io/docs/languages/objective-c/oauth2 Instantiate an RPC object using the configured call options and then start the RPC. ```objectivec GRPCUnaryProtoRPC *rpc = [client unaryCallWithMessage:myRequestMessage responseHandler:myResponseHandler callOptions:options]; [rpc start]; ``` -------------------------------- ### Start a Node.js gRPC Server Source: https://grpc.io/docs/languages/node/basics This snippet demonstrates how to create, bind, and start a gRPC server in Node.js. Ensure the service methods are implemented before starting the server. ```javascript function getServer() { var server = new grpc.Server(); server.addService(routeguide.RouteGuide.service, { getFeature: getFeature, listFeatures: listFeatures, recordRoute: recordRoute, routeChat: routeChat }); return server; } var routeServer = getServer(); routeServer.bindAsync('0.0.0.0:50051', grpc.ServerCredentials.createInsecure(), () => { routeServer.start(); }); ``` -------------------------------- ### Build and Install gRPC and Protocol Buffers (Windows) Source: https://grpc.io/docs/languages/cpp/quickstart Builds and locally installs gRPC and Protocol Buffers using CMake on Windows. It configures the build for installation, disables tests, sets C++ standard to 17, and specifies the installation prefix. ```batch mkdir "cmake\build" pushd "cmake\build" cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_CXX_STANDARD=17 -DCMAKE_INSTALL_PREFIX=%MY_INSTALL_DIR% ..\.. cmake --build . --config Release --target install -j 4 popd ``` -------------------------------- ### Compile gRPC Example Source: https://grpc.io/docs/languages/java/quickstart Compile the client and server components of the gRPC example using the Gradle wrapper. ```bash ./gradlew installDist ``` -------------------------------- ### gRPC Server Startup Source: https://grpc.io/docs/languages/python/basics Starts a gRPC server, adds the RouteGuideServicer, and binds it to a port. ```python def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) route_guide_pb2_grpc.add_RouteGuideServicer_to_server(RouteGuideServicer(), server) server.add_insecure_port("[::]:50051") server.start() server.wait_for_termination() ``` -------------------------------- ### Build and Install gRPC and Protocol Buffers (Linux/macOS) Source: https://grpc.io/docs/languages/cpp/quickstart Builds and locally installs gRPC and Protocol Buffers using CMake on Linux and macOS. It configures the build for installation, disables tests, sets C++ standard to 17, and specifies the installation prefix. ```bash cd grpc mkdir -p cmake/build pushd cmake/build cmake -DgRPC_INSTALL=ON \ -DgRPC_BUILD_TESTS=OFF \ -DCMAKE_CXX_STANDARD=17 \ -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \ ../.. make -j 4 make install popd ``` -------------------------------- ### Install Objective-C Client Library Source: https://grpc.io/docs/languages/objective-c/basics Use Cocoapods to generate and install the Objective-C client library for your .proto files. ```bash pod install ``` -------------------------------- ### Install grpcio-tools Source: https://grpc.io/docs/languages/python/basics Install the necessary package for generating gRPC code. This is a prerequisite for the generation command. ```bash pip install grpcio-tools ``` -------------------------------- ### Install gRPC tools Source: https://grpc.io/docs/languages/python/quickstart Install gRPC tools, including the protocol buffer compiler and plugins for generating Python code from .proto files. ```bash python -m pip install grpcio-tools ``` -------------------------------- ### Start a gRPC Server in Kotlin Source: https://grpc.io/docs/languages/kotlin/basics This snippet demonstrates how to create a gRPC server instance, add a service implementation, start the server, and keep it running until termination. ```kotlin class RouteGuideServer( val port: Int, val features: Collection = Database.features(), val server: Server = ServerBuilder.forPort(port) .addService(RouteGuideService(features)).build() ) { fun start() { server.start() println("Server started, listening on $port") /* ... */ } /* ... */ } fun main(args: Array) { val port = 8980 val server = RouteGuideServer(port) server.start() server.awaitTermination() } ``` -------------------------------- ### Install gRPC-Web Plugin Source: https://grpc.io/docs/platforms/web/basics Install the gRPC-Web protoc plugin globally. This is a prerequisite for generating gRPC-Web service client stubs. ```bash cd grpc-web sudo make install-plugin ``` -------------------------------- ### Compile Proto Files Source: https://grpc.io/docs/languages/php/basics Compile the example's .proto files using the generated protoc and grpc_php_plugin. This step is necessary after building the plugin and navigating to the example's directory. ```bash cd examples/php/route_guide ./route_guide_proto_gen.sh ``` -------------------------------- ### Install Protocol Buffer Go Plugins Source: https://grpc.io/docs/languages/go/quickstart Install the necessary protocol buffer compiler plugins for Go. Ensure your PATH is updated to include the go bin directory. ```go go install google.golang.org/protobuf/cmd/protoc-gen-go@latest go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest ``` ```bash export PATH="$PATH:$(go env GOPATH)/bin" ``` -------------------------------- ### Clone gRPC Go Example Repository Source: https://grpc.io/docs/languages/go/quickstart Download the grpc-go repository to access the example code. This command clones a specific version of the repository. ```bash git clone -b v1.81.1 --depth 1 https://github.com/grpc/grpc-go ``` -------------------------------- ### Install Protobuf Compiler Source: https://grpc.io/docs/languages/objective-c/quickstart Command to install the Protocol Buffer compiler (`protoc`) using Homebrew, which is necessary for building gRPC applications. ```bash brew install protobuf ``` -------------------------------- ### Install Composer Dependencies and Generate Protobuf Code Source: https://grpc.io/docs/languages/php/quickstart Install the necessary `grpc` composer package and generate the PHP protobuf code using the provided script. ```bash ./greeter_proto_gen.sh composer install ``` -------------------------------- ### Clone gRPC Node.js Example Repository Source: https://grpc.io/docs/languages/node/quickstart Clone the official gRPC Node.js repository to obtain the example code for this quick start guide. This command specifically checks out a version tagged for @grpc/grpc-js. ```bash git clone -b @grpc/grpc-js@1.9.0 --depth 1 --shallow-submodules https://github.com/grpc/grpc-node cd grpc-node/examples npm install cd helloworld/dynamic_codegen ``` -------------------------------- ### Run gRPC Server Source: https://grpc.io/docs/languages/cpp/basics Start the gRPC server, specifying the path to the database file. ```bash ./route_guide_server --db_path=path/to/route_guide_db.json ``` -------------------------------- ### Clone gRPC Example Repository Source: https://grpc.io/docs/languages/python/basics Clone the gRPC repository to access example code. Ensure you checkout a specific version for consistency. ```bash git clone -b v1.81.0 --depth 1 --shallow-submodules https://github.com/grpc/grpc ``` -------------------------------- ### Install Protocol Buffers Compiler Source: https://grpc.io/docs/languages/objective-c/quickstart Install the protobuf compiler using Homebrew. This compiler is used to generate code from .proto files. ```bash brew tap grpc/grpc brew install protobuf ``` -------------------------------- ### Troubleshoot gRPC-Go Installation in China Source: https://grpc.io/docs/languages/go/api If you encounter I/O timeout errors when trying to get gRPC-Go from China, use the 'replace' feature in go.mod to alias golang.org packages to their GitHub equivalents. This example shows how to replace google.golang.org/grpc. ```bash $ go mod edit -replace=google.golang.org/grpc=github.com/grpc/grpc-go@latest go mod tidy go mod vendor go build -mod=vendor ``` -------------------------------- ### Install Build Tools with Homebrew Source: https://grpc.io/docs/languages/objective-c/quickstart Install essential build tools like autoconf, automake, libtool, and pkg-config using Homebrew. These are required for compiling gRPC. ```bash brew install autoconf automake libtool pkg-config ``` -------------------------------- ### Install Objective-C Client Dependencies Source: https://grpc.io/docs/languages/objective-c/quickstart Use CocoaPods to install the gRPC client library and other dependencies for the Objective-Chelloworld example. This step generates an Xcode workspace. ```bash cd ../../objective-c/helloworld pod install ``` -------------------------------- ### Clone grpc-dart Repository Source: https://grpc.io/docs/languages/dart/basics Download the example code for the tutorial by cloning the grpc-dart repository. ```bash git clone --depth 1 https://github.com/grpc/grpc-dart ``` -------------------------------- ### Get Dart Packages Source: https://grpc.io/docs/languages/dart/basics Install the necessary Dart packages for your project using the Dart package manager. ```bash dart pub get ``` -------------------------------- ### Build and Start Async Server Source: https://grpc.io/docs/languages/cpp/async Initializes the asynchronous service, server builder, listening port, registers the service, and creates a completion queue. This sets up the basic server infrastructure. ```cpp helloworld::Greeter::AsyncService service; ServerBuilder builder; builder.AddListeningPort("0.0.0.0:50051", InsecureServerCredentials()); builder.RegisterService(&service); auto cq = builder.AddCompletionQueue(); auto server = builder.BuildAndStart(); ``` -------------------------------- ### Bazel Java gRPC Library Rule Source: https://grpc.io/docs/languages/java/generated-code Define gRPC Java libraries using Bazel's `java_grpc_library` rule. This example shows the typical setup for proto definitions and generated code. ```bazel load("@grpc_java//:java_grpc_library.bzl", "java_grpc_library") proto_library( name = "helloworld_proto", srcs = ["src/main/proto/helloworld.proto"], ) java_proto_library( name = "helloworld_java_proto", deps = [":helloworld_proto"], ) java_grpc_library( name = "helloworld_java_grpc", srcs = [":helloworld_proto"], deps = [":helloworld_java_proto"], ) ``` -------------------------------- ### Custom Name Resolver Registration Example Source: https://grpc.io/docs/guides/custom-name-resolution Demonstrates how to register a custom name resolver provider with the gRPC library. The scheme 'my-resolver' will be used to pick up this custom implementation for target strings starting with 'my-resolver:'. ```java public class MyNameResolverProvider extends NameResolverProvider { @Override public NameResolver newNameResolver(URI targetUri, NameResolver.Factory bakın) { // ... implementation ... } @Override protected String getScheme() { return "my-resolver"; } @Override public boolean isAvailable() { return true; } @Override public int priority() { return 1; } // ... other methods ... } // Registration: NameResolverRegistry.getDefaultRegistry().register(new MyNameResolverProvider()); ``` -------------------------------- ### Install Older ActiveSupport and CocoaPods Source: https://grpc.io/docs/languages/objective-c/quickstart Commands to resolve CocoaPods installation errors related to Ruby version requirements by installing a specific older version of `activesupport` before installing CocoaPods. ```bash [sudo] gem install activesupport -v 4.2.6 [sudo] gem install cocoapods ``` -------------------------------- ### Install CMake (Windows) Source: https://grpc.io/docs/languages/cpp/quickstart Installs CMake version 3.16 or later on Windows using Chocolatey. Verify the installation by checking the version. ```powershell choco install cmake ``` ```powershell cmake --version ``` -------------------------------- ### Install CMake (macOS) Source: https://grpc.io/docs/languages/cpp/quickstart Installs CMake version 3.16 or later on macOS using Homebrew. Verify the installation by checking the version. ```bash brew install cmake ``` ```bash cmake --version ``` -------------------------------- ### Go gRPC Server Startup Source: https://grpc.io/docs/languages/go/basics Set up and start a gRPC server in Go. This involves listening on a TCP port, creating a new server instance, registering the service, and serving requests. ```go lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", port)) if err != nil { log.Fatalf("failed to listen: %v", err) } var opts []grpc.ServerOption ... grpcServer := grpc.NewServer(opts...) pb.RegisterRouteGuideServer(grpcServer, newServer()) grpcServer.Serve(lis) ``` -------------------------------- ### Install CMake (Linux) Source: https://grpc.io/docs/languages/cpp/quickstart Installs CMake version 3.16 or later on Linux using apt. Verify the installation by checking the version. ```bash sudo apt install -y cmake ``` ```bash cmake --version ``` -------------------------------- ### Run gRPC Server Source: https://grpc.io/docs/languages/go/quickstart Compile and execute the gRPC server code from the examples/helloworld directory. ```go go run greeter_server/main.go ``` -------------------------------- ### Install Local CMake Version (Linux) Source: https://grpc.io/docs/languages/cpp/quickstart Installs a specific, more recent version of CMake into the local installation directory on Linux. This is useful if the system-wide version is outdated. ```bash wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3.30.3/cmake-3.30.3-linux-x86_64.sh sh cmake-linux.sh -- --skip-license --prefix=$MY_INSTALL_DIR rm cmake-linux.sh ``` -------------------------------- ### Run Dart gRPC Server Source: https://grpc.io/docs/languages/dart/quickstart Execute this command from the 'example/helloworld' directory to start the Dart gRPC server. ```bash dart bin/server.dart ``` -------------------------------- ### Run Tonic Routeguide Server Source: https://grpc.io/docs/languages/rust/basics Command to start the gRPC routeguide server using Cargo. ```bash cargo run --bin routeguide-server ``` -------------------------------- ### Run gRPC Client Source: https://grpc.io/docs/languages/go/quickstart Compile and execute the gRPC client code from the examples/helloworld directory to interact with the server. ```go go run greeter_client/main.go ``` -------------------------------- ### Build Client and Server (Linux/macOS) Source: https://grpc.io/docs/languages/cpp/quickstart Build the client and server applications using make after updating the code. Ensure you are in the example's build directory. ```bash make -j 4 ``` -------------------------------- ### Install gRPC Gem Source: https://grpc.io/docs/languages/ruby/quickstart Install the gRPC library for Ruby. This is a prerequisite for using gRPC in your Ruby projects. ```bash gem install grpc ``` -------------------------------- ### Install gRPCio Source: https://grpc.io/docs/languages/python/quickstart Install the gRPCio package for Python. This package provides the necessary libraries for gRPC communication. ```bash python -m pip install grpcio ``` ```bash sudo python -m pip install grpcio ``` -------------------------------- ### Install gRPC NPM Package Source: https://grpc.io/docs/languages/node/api Use this command to install the gRPC NPM package for your Node.js project. ```bash npm install grpc ``` -------------------------------- ### Run gRPC Server in Ruby Source: https://grpc.io/docs/languages/ruby/basics Start the RouteGuide gRPC server using Bundler. The server requires a path to a database file. ```bash bundle exec route_guide/route_guide_server.rb ../python/route_guide/route_db.json ``` -------------------------------- ### RouteGuideService Implementation Source: https://grpc.io/docs/languages/dart/basics Example implementation of the RouteGuideService, extending the generated RouteGuideServiceBase. It includes methods for handling different RPC types. ```APIDOC ## RouteGuideService ### Description Implements the gRPC service interface for RouteGuide. This class handles incoming requests and dispatches them to the appropriate logic. ### Methods - `getFeature(grpc.ServiceCall call, Point request)`: Handles a simple RPC to retrieve feature information for a given point. - `listFeatures(grpc.ServiceCall call, Rectangle request)`: Handles a server-side streaming RPC to return a stream of features within a specified rectangle. - `recordRoute(grpc.ServiceCall call, Stream request)`: Handles a client-side streaming RPC to record a route based on a stream of points. - `routeChat(grpc.ServiceCall call, Stream request)`: Handles a bi-directional streaming RPC for real-time chat messages related to routes. ``` -------------------------------- ### Build Client and Server (Windows) Source: https://grpc.io/docs/languages/cpp/quickstart Build the client and server applications using cmake on Windows after updating the code. Ensure you are in the example's build directory. ```bash cmake --build . --config Release -j 4 ``` -------------------------------- ### Navigate to Objective-C Auth Sample Source: https://grpc.io/docs/languages/objective-c/oauth2 Change directory to the Objective-C OAuth2 authentication sample within the cloned gRPC repository. ```bash cd examples/objective-c/auth_sample ``` -------------------------------- ### Implement RouteGuide Server Interface in Go Source: https://grpc.io/docs/languages/go/basics Defines the structure for a RouteGuide server and its methods. This is the starting point for implementing gRPC services in Go. ```go type routeGuideServer struct { ... } ... func (s *routeGuideServer) GetFeature(ctx context.Context, point *pb.Point) (*pb.Feature, error) { ... } ... func (s *routeGuideServer) ListFeatures(rect *pb.Rectangle, stream pb.RouteGuide_ListFeaturesServer) error { ... } ... func (s *routeGuideServer) RecordRoute(stream pb.RouteGuide_RecordRouteServer) error { ... } ... func (s *routeGuideServer) RouteChat(stream pb.RouteGuide_RouteChatServer) error { ... } ... ``` -------------------------------- ### RouteGuide Client Constructor with Host and Port Source: https://grpc.io/docs/languages/java/basics Initializes a gRPC client connecting to a specified host and port using plaintext transport. Used for creating the channel and stubs. ```java public RouteGuideClient(String host, int port) { this(ManagedChannelBuilder.forAddress(host, port).usePlaintext()); } /** Construct client for accessing RouteGuide server using the existing channel. */ public RouteGuideClient(ManagedChannelBuilder channelBuilder) { channel = channelBuilder.build(); blockingStub = RouteGuideGrpc.newBlockingStub(channel); asyncStub = RouteGuideGrpc.newStub(channel); } ``` -------------------------------- ### Install Node.js Dependencies Source: https://grpc.io/docs/languages/node/basics Installs all necessary packages for a Node.js project. Run this command in your project's root directory. ```bash npm install ``` -------------------------------- ### Start a gRPC Server in C++ Source: https://grpc.io/docs/languages/cpp/basics Use ServerBuilder to configure and launch a gRPC server. Ensure the service implementation is registered and the server is listening on the specified address. ```cpp void RunServer(const std::string& db_path) { std::string server_address("0.0.0.0:50051"); RouteGuideImpl service(db_path); ServerBuilder builder; builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); builder.RegisterService(&service); std::unique_ptr server(builder.BuildAndStart()); std::cout << "Server listening on " << server_address << std::endl; server->Wait(); } ``` -------------------------------- ### Install protoc-gen-dart Plugin Source: https://grpc.io/docs/languages/dart/quickstart Install the protocol buffer compiler plugin for Dart. Ensure your PATH is updated to include the plugin. ```bash dart pub global activate protoc_plugin ``` ```bash export PATH="$PATH:$HOME/.pub-cache/bin" ``` -------------------------------- ### Shutdown gRPC-Web Example Services Source: https://grpc.io/docs/platforms/web/quickstart Stop and remove the Docker containers and networks created by Docker Compose for the gRPC-Web example. ```bash docker-compose down ``` -------------------------------- ### Bidirectional-Streaming Call Usage Example Source: https://grpc.io/docs/languages/rust/generated-code This example demonstrates how to interact with a bidirectional-streaming gRPC call. It shows how to initiate the call, spawn a task for sending messages, and concurrently receive responses. The example also covers handling stream termination and retrieving the final RPC status. ```rust // Begin the call: let (mut tx, mut rx) = client.foo().await; // Spawn a task for sending requests: let handle = tokio::task::spawn(async move { while let Some(message) = get_message_to_send() { if tx.send(message).is_err() { // Stream terminated while sending messages. return; } } // Explicitly signal the client is done sending; note that this // happens implicitly when tx is dropped. tx.close(); }); // In parallel with the task above, receive responses: while let Some(response: ResponseMsg) = rx.recv().await { // Process "response" } // Receive the final status of the RPC: let status: Status = rx.status().await; ``` -------------------------------- ### Construct a gRPC Client in PHP Source: https://grpc.io/docs/languages/php/basics Instantiate a RouteGuideClient object to connect to the gRPC server. Ensure the server address and port are correctly specified. Use createInsecure() for development or when security is handled by other means. ```php $client = new Routeguide\RouteGuideClient('localhost:50051', [ 'credentials' => Grpc\ChannelCredentials::createInsecure(), ]); ``` -------------------------------- ### Build and Install gRPC Client on Android Device Source: https://grpc.io/docs/platforms/android/java/quickstart Build the Android gRPC client application and install it on your connected device or emulator. ```bash (cd android/helloworld; ../../gradlew installDebug) ``` -------------------------------- ### Install gRPC Tools Gem Source: https://grpc.io/docs/languages/ruby/quickstart Install the gRPC tools for Ruby, which include the protocol buffer compiler and code generation plugins. ```bash gem install grpc-tools ``` -------------------------------- ### Create gRPC Client Stub Source: https://grpc.io/docs/languages/node/basics Instantiate a RouteGuide stub by providing the server address and insecure credentials. This is the first step to calling service methods. ```javascript new routeguide.RouteGuide('localhost:50051', grpc.credentials.createInsecure()); ``` -------------------------------- ### C++ Initiating and Awaiting RPC Source: https://grpc.io/docs/languages/cpp/callback Demonstrates how to instantiate the `Recorder` client reactor to initiate a gRPC call and then wait for its completion using the `Await` method. It also shows how to process the results or handle errors. ```cpp Recorder recorder(stub_.get(), kCoordFactor_, &feature_list_); RouteSummary stats; Status status = recorder.Await(&stats); if (status.ok()) { std::cout << "Finished trip with " << stats.point_count() << " points\n" << "Passed " << stats.feature_count() << " features\n" << "Travelled " << stats.distance() << " meters\n" << "It took " << stats.elapsed_time() << " seconds" << std::endl; } else { std::cout << "RecordRoute rpc failed." << std::endl; } ``` -------------------------------- ### Create New Server Source: https://grpc.io/docs/languages/go/api Creates a new gRPC server instance. Use this to initialize a server before registering services or accepting requests. ```go func NewServer(opt ...ServerOption) *Server ```