TCP Client
The ClientChannel class represents a communication channel on which you can make requests to server device. Channel presents the same interface once you create it,
regardless of the underlying transport. You can create a TCP client channel using create_tcp method.
In Rust, you can use the spawn_tcp_client_task to create a channel and spawn the runner task in the current runtime.
Otherwise, you can use create_tcp_handle_and_task and manually spawn the returned future when ready.
- Rust
- C
- C++
- Java
- C#
let channel = spawn_tcp_client_task(
HostAddr::ip(IpAddr::V4(Ipv4Addr::LOCALHOST), 502),
1,
default_retry_strategy(),
DecodeLevel::default(),
Some(Box::new(LoggingListener)),
);
rodbus_client_channel_t* channel = NULL;
rodbus_decode_level_t decode_level = rodbus_decode_level_nothing();
rodbus_param_error_t err = rodbus_client_channel_create_tcp(runtime, "127.0.0.1", 502, 1, rodbus_retry_strategy_init(), decode_level, get_client_listener(), &channel);
if (err) {
printf("Unable to initialize channel: %s\n", rodbus_param_error_to_string(err));
return -1;
}
auto channel = rodbus::ClientChannel::create_tcp(
runtime,
"127.0.0.1",
502,
100,
rodbus::RetryStrategy(),
rodbus::DecodeLevel::nothing(),
std::make_unique<PrintingClientStateListener>()
);
ClientChannel channel = ClientChannel.createTcp(runtime, "127.0.0.1", ushort(502), ushort(100), new RetryStrategy(), DecodeLevel.nothing(), new PrintingClientStateListener());
var channel = ClientChannel.CreateTcp(runtime, "127.0.0.1", 502, 1, new RetryStrategy(), DecodeLevel.Nothing(), new ClientStateListener());
Maximum Queued Requests
Each channel sends one request at a time and has a fixed-length buffer of requests to send.
Endpoint Configuration
The argument for the remote endpoint is a string in format the <host>:<port> where "host" must be one of the following:
- IPv4 address
- IPv6 address
- DNS name (library will perform DNS name resolution internally)
Retry Strategy
A TCP channel tries to establish and maintain a connection as soon as it is created. To avoid flooding, reconnection delays are applied.
The RetryStrategy controls the rate at which the client retries failed connection attempts. The client uses exponential backoff when attempting to establish
a connection. The delay between attempts doubles from min_delay up to max_delay.
Decode Level
See logging configuration page for more details.