#include <iostream>
#include <string>
{
std::cout << "=== gRPC Service Example ===" << std::endl;
std::cout << "\n1. gRPC Server configuration:" << std::endl;
config.keepalive_time = std::chrono::milliseconds(7200000);
config.keepalive_timeout = std::chrono::milliseconds(20000);
std::cout <<
" Max concurrent streams: " <<
config.max_concurrent_streams << std::endl;
std::cout <<
" Worker threads: " <<
config.num_threads << std::endl;
std::cout <<
" Keepalive: " <<
config.keepalive_time.count() <<
"ms" << std::endl;
std::cout << "\n2. Creating gRPC server:" << std::endl;
auto reg_result = server.register_unary_method(
"/example.Greeter/SayHello",
{
std::cout <<
" [Handler] Received request (" << request.
data.size()
<< " bytes)" << std::endl;
std::string body = "Hello from gRPC server!";
response.
data.assign(body.begin(), body.end());
return kcenon::common::ok(std::move(response));
});
if (reg_result.is_ok())
{
std::cout << " Method '/example.Greeter/SayHello' registered" << std::endl;
}
else
{
std::cout << " Method registration: " << reg_result.error().message << std::endl;
}
std::cout << "\n3. gRPC Client:" << std::endl;
std::cout << " Target: localhost:50051" << std::endl;
std::cout << " (Connection requires a running server)" << std::endl;
std::cout << "\n4. gRPC API overview:" << std::endl;
std::cout << " Server: register_unary_method(), start(port), stop()" << std::endl;
std::cout << " Client: connect(), call_raw(method, request, options)" << std::endl;
std::cout << " Message: grpc_message { data: vector<byte> }" << std::endl;
std::cout << "\nDone." << std::endl;
return 0;
}
gRPC server for handling RPC requests
Context for handling a single RPC request.
Unified gRPC protocol header.
Main namespace for all Network System components.
gRPC message with compression flag and payload
std::vector< uint8_t > data
Message payload.
Configuration for gRPC server.
size_t max_concurrent_streams
Maximum number of concurrent streams per connection.