Skip to main content

TCP client

Create a TCP client channel with the runtime, the channel configuration, the endpoints to connect to, and a ClientStateListener.

let channel = spawn_master_tcp_client(
LinkErrorMode::Close,
get_master_channel_config(master_address)?,
EndpointList::new(endpoint.to_string(), &[]),
ConnectStrategy::default(),
LogListener::create("client"),
);
note

The function is called within the context of the Tokio runtime, and is therefore implicit in Rust.

EndpointList​

An EndpointList contains remote endpoints the master will try to connect to. It must have at least one entry; additional entries serve as backups. The channel tries each endpoint in order, back to back, until one connects. After a successful connection, the next attempt starts again at the first endpoint. Each endpoint is a <host>:<port> tuple where "host" is:

  • IPv4 address
  • IPv6 address
  • Domain name

ConnectStrategy​

The ConnectStrategy controls the rate at which the master retries failed connection attempts. The master uses exponential backoff when attempting to establish a connection. Each time every endpoint in the list fails, the master waits before trying the list again. This delay doubles from minConnectDelay up to maxConnectDelay. If a connection fails after previously connecting, it will wait reconnectDelay before the next attempt.