class

GRPC::Server

Inherits Reference < Object

Server hosts registered gRPC services and dispatches incoming RPCs.

Plain TCP example: server = GRPC::Server.new server.handle GreeterImpl.new server.listen "0.0.0.0", 50051

TLS example: server = GRPC::Server.new server.use_tls(cert: "server.crt", key: "server.key") server.handle GreeterImpl.new server.listen "0.0.0.0", 50051

Constants

LOGGER = ::Log.for(self)

Constructors

new(transport_factory : ServerTransportFactory | Nil = nil)
Source

Instance methods

bind(address : String) : self

bind sets up the TCP listener without starting the serve loop. Call serve (or start for non-blocking) afterward.

Source
enable_health_checking(default_status : Grpc::Health::V1::HealthCheckResponse::ServingStatus = ::Grpc::Health::V1::HealthCheckResponse::ServingStatus::SERVING) : Health::Reporter

enable_health_checking registers the built-in health service and returns its reporter. Calling this multiple times returns the same instance.

Source
enable_reflection

enable_reflection registers the built-in reflection service and returns it. Register FileDescriptorProto bytes on the returned service via add_file_descriptor.

Source
handle(service : Service) : self

handle registers a service implementation with the server.

Source
intercept(interceptor : ServerInterceptor) : self

intercept registers a server-side interceptor. Interceptors run outermost-first (first registered wraps all others). Must be called before listen/bind.

Source
listen(host : String, port : Int32) : Nil

listen binds to the given host and port and starts serving. Blocks until stopped.

Source
listen(host : String, port : String) : Nil

listen with port as a string.

Source
listen(address : String) : Nil

listen with a combined "host:port" address string.

Source
reflection_service?

Returns the registered reflection service if enabled.

Source
serve

serve starts the accept loop. Blocks until stopped.

Source
start

start runs the server in a background fiber, returning immediately. Useful for tests and embedded servers.

Source
stop
Source
use_tls(cert : String, key : String) : self

use_tls configures the server to accept TLS connections. cert is the path to the PEM-encoded certificate chain file. key is the path to the PEM-encoded private key file. Must be called before listen/bind.

Source
use_tls(context : OpenSSL::SSL::Context::Server) : self

use_tls with a pre-built OpenSSL context for full control over TLS settings.

Source

Nested types