TCP Client

Once created, a MasterChannel presents the same interface regardless of the underlying transport. A TCP client channel is created using the runtime, some configuration, and a callback for observering to the status of the connection.

let mut channel = spawn_master_tcp_client(
LinkErrorMode::Close,
get_master_channel_config()?,
EndpointList::new("127.0.0.1:20000".to_owned(), &[]),
ConnectStrategy::default(),
NullListener::create(),
);
note

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

Enabling#

A MasterChannel will not begin communications until the enable method is called. This gives the user the chance to configure all of the associations on the channel as we'll discuss on the next page. The user may also disable on the channel to put it in an inactive state.

LinkErrorMode#

The LinkErrorMode controls what happens if framing error is detected at the link-layer. TCP is a lossless transport so the default behavior is to close the connection. You can, however, treat the TCP more like a serial port by changing this setting to LinkErrorMode::Discard.

EndpointList#

An EndpointList is a list of remote endpoints to which the master will try to connect. It must contain at least one entry and optionally additional backup addresses. The channel will round-robin through this list until a connection is established. The list may contain:

Endpoints consist of a <host>:<port> tuple where "host" is one of the following:

  • 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. The delay between attempts doubles from minConnectDelay up to maxConnectDelay. If a connection fails after being previously connected, it will wait reconnectDelay before the next attempt.

ClientStateListener#

The ClientStateListener interface has a single method that informs the application about the state of connection.