server

fun server(port: Int = -1, tlsContext: TlsContext = PLAINTEXT_CONTEXT, inProcessServerName: String = "", bindAddress: String? = null, block: ServerBuilder<*>.() -> Unit): Server

Builds a gRPC Server using either a Netty transport or an in-process transport.

When inProcessServerName is non-empty, an in-process server is created (ignoring port, TLS and bind address). Otherwise a Netty server is created listening on port, at bindAddress or on every interface.

A Netty server is plaintext unless tlsContext carries a certificate, since there is none to default to. A plaintext server that listens on every interface, or on a bindAddress that is not a loopback address, logs a WARN, since its RPCs and metadata, credentials included, cross the network unencrypted.

Return

the built Server

Parameters

port

the port to listen on (Netty transport only); 0 lets the OS choose one

tlsContext

the TLS configuration for the server; defaults to PLAINTEXT_CONTEXT. Pass a context from TlsUtils.buildServerTlsContext to serve TLS

inProcessServerName

if non-empty, creates an in-process server with this name

bindAddress

the address to listen on, such as "127.0.0.1" (Netty transport only); null, the default, listens on every interface. Surrounding whitespace is trimmed, and a host name is resolved when the server is built

block

a configuration block applied to the server builder before building

Throws

if the Netty transport is chosen and port is not in 0..65535, or bindAddress is blank or does not resolve to an IP address