pub struct Client { /* private fields */ }
Expand description
Wrapper around common data for generating sessions and performing requests with one-shot connections.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(config: ClientConfig) -> Self
pub fn new(config: ClientConfig) -> Self
Create a new client from config.
Note that this does not make any connection to the server.
§Arguments
config
- Client configuration object.
Sourcepub fn session_builder(&self) -> SessionBuilder<'_, (), ()>
pub fn session_builder(&self) -> SessionBuilder<'_, (), ()>
Get a new session builder that can be used to build a session dynamically.
Sourcepub async fn connect_to_endpoint_id(
&mut self,
endpoint_id: impl Into<String>,
) -> Result<(Arc<Session>, SessionEventLoop), StatusCode>
pub async fn connect_to_endpoint_id( &mut self, endpoint_id: impl Into<String>, ) -> Result<(Arc<Session>, SessionEventLoop), StatusCode>
Connects to a named endpoint that you have defined in the ClientConfig
and creates a Session
for that endpoint. Note that GetEndpoints
is first
called on the server and it is expected to support the endpoint you intend to connect to.
§Returns
Ok((Arc<Session>, SessionEventLoop))
- Session and event loop.Err(StatusCode)
- Request failed, Status code is the reason for failure.
Sourcepub async fn connect_to_matching_endpoint(
&mut self,
endpoint: impl Into<EndpointDescription>,
user_identity_token: IdentityToken,
) -> Result<(Arc<Session>, SessionEventLoop), StatusCode>
pub async fn connect_to_matching_endpoint( &mut self, endpoint: impl Into<EndpointDescription>, user_identity_token: IdentityToken, ) -> Result<(Arc<Session>, SessionEventLoop), StatusCode>
Connects to an ad-hoc server endpoint description.
This function returns both a reference to the session, and a SessionEventLoop
. You must run and
poll the event loop in order to actually establish a connection.
This method will not attempt to create a session on the server, that will only happen once you start polling the session event loop.
§Arguments
endpoint
- Discovery endpoint, the client will first connect to this in order to get a list of the available endpoints on the server.user_identity_token
- Identity token to use for authentication.
§Returns
Ok((Arc<Session>, SessionEventLoop))
- Session and event loop.Err(StatusCode)
- Request failed, Status code is the reason for failure.
Sourcepub fn connect_to_endpoint_directly(
&mut self,
endpoint: impl Into<EndpointDescription>,
identity_token: IdentityToken,
) -> Result<(Arc<Session>, SessionEventLoop), String>
pub fn connect_to_endpoint_directly( &mut self, endpoint: impl Into<EndpointDescription>, identity_token: IdentityToken, ) -> Result<(Arc<Session>, SessionEventLoop), String>
Connects to a server directly using provided EndpointDescription
.
This function returns both a reference to the session, and a SessionEventLoop
. You must run and
poll the event loop in order to actually establish a connection.
This method will not attempt to create a session on the server, that will only happen once you start polling the session event loop.
§Arguments
endpoint
- Endpoint to connect to.identity_token
- Identity token for authentication.
§Returns
Ok((Arc<Session>, SessionEventLoop))
- Session and event loop.Err(String)
- Endpoint is invalid.
Sourcepub async fn connect_to_default_endpoint(
&mut self,
) -> Result<(Arc<Session>, SessionEventLoop), String>
pub async fn connect_to_default_endpoint( &mut self, ) -> Result<(Arc<Session>, SessionEventLoop), String>
Creates a new Session
using the default endpoint specified in the config. If
there is no default, or the endpoint does not exist, this function will return an error
This function returns both a reference to the session, and a SessionEventLoop
. You must run and
poll the event loop in order to actually establish a connection.
This method will not attempt to create a session on the server, that will only happen once you start polling the session event loop.
§Arguments
endpoints
- A list ofEndpointDescription
containing the endpoints available on the server.
§Returns
Ok((Arc<Session>, SessionEventLoop))
- Session and event loop.Err(String)
- Endpoint is invalid.
Sourcepub fn default_endpoint(&self) -> Result<ClientEndpoint, String>
pub fn default_endpoint(&self) -> Result<ClientEndpoint, String>
Gets the ClientEndpoint
information for the default endpoint, as defined
by the configuration. If there is no default endpoint, this function will return an error.
§Returns
Ok(ClientEndpoint)
- The default endpoint set in config.Err(String)
- No default endpoint could be found.
Sourcepub async fn get_server_endpoints(
&self,
) -> Result<Vec<EndpointDescription>, StatusCode>
pub async fn get_server_endpoints( &self, ) -> Result<Vec<EndpointDescription>, StatusCode>
Get the list of endpoints for the server at the configured default endpoint.
§Returns
Ok(Vec<EndpointDescription>)
- A list of the available endpoints on the server.Err(StatusCode)
- Request failed, Status code is the reason for failure.
Sourcepub async fn get_server_endpoints_from_url(
&self,
server_url: impl Into<String>,
) -> Result<Vec<EndpointDescription>, StatusCode>
pub async fn get_server_endpoints_from_url( &self, server_url: impl Into<String>, ) -> Result<Vec<EndpointDescription>, StatusCode>
Get the list of endpoints for the server at the given URL.
§Arguments
server_url
- URL of the discovery server to get endpoints from.
§Returns
Ok(Vec<EndpointDescription>)
- A list of the available endpoints on the server.Err(StatusCode)
- Request failed, Status code is the reason for failure.
Sourcepub async fn get_endpoints(
&self,
server_url: impl Into<String>,
locale_ids: &[&str],
profile_uris: &[&str],
) -> Result<Vec<EndpointDescription>, StatusCode>
pub async fn get_endpoints( &self, server_url: impl Into<String>, locale_ids: &[&str], profile_uris: &[&str], ) -> Result<Vec<EndpointDescription>, StatusCode>
Get the list of endpoints for the server at the given URL.
§Arguments
server_url
- URL of the discovery server to get endpoints from.locale_ids
- List of required locale IDs on the given server endpoint.profile_uris
- Returned endpoints should match one of these profile URIs.
§Returns
Ok(Vec<EndpointDescription>)
- A list of the available endpoints on the server.Err(StatusCode)
- Request failed, Status code is the reason for failure.
Sourcepub async fn find_servers(
&self,
discovery_endpoint_url: impl Into<String>,
locale_ids: Option<Vec<UAString>>,
server_uris: Option<Vec<UAString>>,
) -> Result<Vec<ApplicationDescription>, StatusCode>
pub async fn find_servers( &self, discovery_endpoint_url: impl Into<String>, locale_ids: Option<Vec<UAString>>, server_uris: Option<Vec<UAString>>, ) -> Result<Vec<ApplicationDescription>, StatusCode>
Connects to a discovery server and asks the server for a list of
available servers’ ApplicationDescription
.
§Arguments
discovery_endpoint_url
- Discovery endpoint to connect to.locale_ids
- List of locales to use.server_uris
- List of servers to return. If empty, all known servers are returned.
§Returns
Ok(Vec<ApplicationDescription>)
- List of descriptions for servers known to the discovery server.Err(StatusCode)
- Request failed, Status code is the reason for failure.
Sourcepub async fn find_servers_on_network(
&self,
discovery_endpoint_url: impl Into<String>,
starting_record_id: u32,
max_records_to_return: u32,
server_capability_filter: Option<Vec<UAString>>,
) -> Result<FindServersOnNetworkResponse, StatusCode>
pub async fn find_servers_on_network( &self, discovery_endpoint_url: impl Into<String>, starting_record_id: u32, max_records_to_return: u32, server_capability_filter: Option<Vec<UAString>>, ) -> Result<FindServersOnNetworkResponse, StatusCode>
Connects to a discovery server and asks for a list of available servers on the network.
See OPC UA Part 4 - Services 5.5.3 for a complete description of the service.
§Arguments
discovery_endpoint_url
- Endpoint URL to connect to.starting_record_id
- Only records with an identifier greater than this number will be returned.max_records_to_return
- The maximum number of records to return in the response. 0 indicates that there is no limit.server_capability_filter
- List of server capability filters. Only records with all the specified server capabilities are returned.
§Returns
Ok(FindServersOnNetworkResponse)
- Full service response object.Err(StatusCode)
- Request failed, Status code is the reason for failure.
Sourcepub fn find_matching_endpoint(
endpoints: &[EndpointDescription],
endpoint_url: &str,
security_policy: SecurityPolicy,
security_mode: MessageSecurityMode,
) -> Option<EndpointDescription>
pub fn find_matching_endpoint( endpoints: &[EndpointDescription], endpoint_url: &str, security_policy: SecurityPolicy, security_mode: MessageSecurityMode, ) -> Option<EndpointDescription>
Find an endpoint supplied from the list of endpoints that matches the input criteria.
§Arguments
endpoints
- List of available endpoints on the server.endpoint_url
- Given endpoint URL.security_policy
- Required security policy.security_mode
- Required security mode.
§Returns
Some(EndpointDescription)
- Validated endpoint.None
- No matching endpoint was found.
Sourcepub fn is_supported_endpoint(&self, endpoint: &EndpointDescription) -> bool
pub fn is_supported_endpoint(&self, endpoint: &EndpointDescription) -> bool
Sourcepub async fn register_server(
&mut self,
discovery_endpoint_url: impl Into<String>,
server: RegisteredServer,
) -> Result<(), StatusCode>
pub async fn register_server( &mut self, discovery_endpoint_url: impl Into<String>, server: RegisteredServer, ) -> Result<(), StatusCode>
This function is used by servers that wish to register themselves with a discovery server.
i.e. one server is the client to another server. The server sends a RegisterServerRequest
to the discovery server to register itself. Servers are expected to re-register themselves periodically
with the discovery server, with a maximum of 10 minute intervals.
See OPC UA Part 4 - Services 5.4.5 for complete description of the service and error responses.
§Arguments
server
- The server to register
§Returns
Ok(())
- SuccessErr(StatusCode)
- Request failed, Status code is the reason for failure.
Sourcepub fn certificate_store(&self) -> &Arc<RwLock<CertificateStore>>
pub fn certificate_store(&self) -> &Arc<RwLock<CertificateStore>>
Get the certificate store.