pub struct ConnectOptions<'a> {
pub username: Option<&'a str>,
pub password: Option<&'a str>,
pub timeout: Option<Duration>,
pub reconnect: ReconnectBehavior,
pub tls_config: Option<Arc<ClientConfig>>,
pub reconnector: Option<Arc<dyn Reconnector>>,
pub keepalive: KeepaliveBehavior,
}Fields§
§username: Option<&'a str>§password: Option<&'a str>§timeout: Option<Duration>§reconnect: ReconnectBehaviorWhether the returned client should reconnect automatically when the WebSocket
connection drops. Defaults to ReconnectBehavior::Enabled(ReconnectPolicy::default()) -
set this to ReconnectBehavior::Disabled to get the old one-shot-connection behavior.
tls_config: Option<Arc<ClientConfig>>Custom TLS trust config for wss:// addresses. None (the default) uses
tokio-tungstenite’s built-in rustls-tls-webpki-roots default, which only trusts
public CAs - it cannot validate a CSMS certificate issued by a private/internal CA.
Build a rustls::ClientConfig with a RootCertStore containing that CA’s certificate
(and optionally client-cert auth for mTLS) and set it here to connect to such a CSMS.
ocpp_client::rustls re-exports the exact rustls version this crate was built
against, so the ClientConfig you build is guaranteed compatible. Reconnect attempts
(see reconnect above) reuse the same config.
reconnector: Option<Arc<dyn Reconnector>>Decides where a dropped connection is redialled. None (the default) redials the same
address, protocol, credentials and TLS config the connection started with, which is what
almost every caller wants.
Supply one to make the redial target something other than a constant - the case this
exists for is a charge point that must move to a different CSMS address (an OCPP 2.x
network connection profile, a failover endpoint) without tearing down its Client.
Reconnecting through the same Client keeps its identity, so every registered handler,
every in-flight request and every queued message survives the move; dropping the client
and calling connect_* again does not.
Implementations usually delegate to websocket_transport rather than building a
transport by hand - see its docs for a worked reconnector. A custom reconnector is fully
responsible for the redial: address and the credential/TLS fields above apply to the
initial connection only and are not consulted when it runs.
ReconnectBehavior::Disabled still wins - it is an explicit “do not redial”, and
supplying a reconnector does not quietly turn reconnect back on.
keepalive: KeepaliveBehaviorWhether the client pings the CSMS on a schedule, and when it gives up on an unresponsive
one and redials. Defaults to KeepaliveBehavior::Enabled with
KeepalivePolicy::default() - a 60-second interval, tolerating one missed pong.
Keepalive is on by default here for the same reason reconnect is: without it, a
half-open connection (a NAT table entry dropped, a mobile link that went away without a
FIN) is invisible, and the reconnect machinery never gets a chance to fire because the
read loop is parked in recv until the OS TCP timeout. Set KeepaliveBehavior::Disabled
if the CSMS pings the charge point instead, or if the deployment forbids unsolicited
traffic.
The interval is also readable and writable at runtime via Client::ping_interval/
Client::set_ping_interval, which is how WebSocketPingInterval gets reported to, and
updated by, a CSMS.
Trait Implementations§
Source§impl<'a> Clone for ConnectOptions<'a>
impl<'a> Clone for ConnectOptions<'a>
Source§fn clone(&self) -> ConnectOptions<'a>
fn clone(&self) -> ConnectOptions<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ConnectOptions<'_>
impl Debug for ConnectOptions<'_>
Source§impl Default for ConnectOptions<'_>
Hand-written rather than derived because keepalive defaults to enabled, unlike
KeepaliveBehavior’s own Default - see the field’s docs for why the WebSocket convenience
path opts in where the bare Client constructors don’t.
impl Default for ConnectOptions<'_>
Hand-written rather than derived because keepalive defaults to enabled, unlike
KeepaliveBehavior’s own Default - see the field’s docs for why the WebSocket convenience
path opts in where the bare Client constructors don’t.