TCP client
Create a TCP client channel with the runtime, the channel configuration, the endpoints to connect to, and a ClientStateListener.
- Rust
- C
- C++
- Java
- C#
let channel = spawn_master_tcp_client(
LinkErrorMode::Close,
get_master_channel_config(master_address)?,
EndpointList::new(endpoint.to_string(), &[]),
ConnectStrategy::default(),
LogListener::create("client"),
);
The function is called within the context of the Tokio runtime, and is therefore implicit in Rust.
dnp3_master_channel_t *channel = NULL;
dnp3_endpoint_list_t *endpoints = dnp3_endpoint_list_create(endpoint);
dnp3_param_error_t err = dnp3_master_channel_create_tcp(
runtime,
DNP3_LINK_ERROR_MODE_CLOSE,
get_master_channel_config(),
endpoints,
dnp3_connect_strategy_init(),
get_client_state_listener(),
&channel
);
dnp3_endpoint_list_destroy(endpoints);
// check error
dnp3::EndpointList endpoints(endpoint);
auto channel = dnp3::MasterChannel::create_tcp_channel(
runtime,
dnp3::LinkErrorMode::close,
get_master_channel_config(),
endpoints,
dnp3::ConnectStrategy(),
create_client_state_listener()
);
MasterChannel channel =
MasterChannel.createTcpChannel(
runtime,
LinkErrorMode.CLOSE,
getMasterChannelConfig(),
new EndpointList(endpoint),
new ConnectStrategy(),
state -> System.out.println("client state: " + state));
var channel = MasterChannel.CreateTcpChannel(
runtime,
LinkErrorMode.Close,
GetMasterChannelConfig(),
new EndpointList(endpoint),
new ConnectStrategy(),
new LogListener("client")
);
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.