pub struct UnifiedAsyncClient { /* private fields */ }
Expand description
Unified async OpenIGTLink client
Supports optional TLS encryption and automatic reconnection without combinatorial type explosion.
§Examples
use openigtlink_rust::io::unified_async_client::UnifiedAsyncClient;
// Plain TCP client
let client = UnifiedAsyncClient::connect("127.0.0.1:18944").await?;
// With TLS
let tls_config = rustls::ClientConfig::builder()
.with_root_certificates(rustls::RootCertStore::empty())
.with_no_client_auth();
let client = UnifiedAsyncClient::connect_with_tls(
"localhost",
18944,
std::sync::Arc::new(tls_config)
).await?;
Implementations§
Source§impl UnifiedAsyncClient
impl UnifiedAsyncClient
Sourcepub async fn connect_with_tls(
hostname: &str,
port: u16,
tls_config: Arc<ClientConfig>,
) -> Result<Self>
pub async fn connect_with_tls( hostname: &str, port: u16, tls_config: Arc<ClientConfig>, ) -> Result<Self>
Connect to a TLS-enabled server
§Arguments
hostname
- Server hostname (for SNI)port
- Server porttls_config
- TLS client configuration
Sourcepub fn with_reconnect(self, config: ReconnectConfig) -> Self
pub fn with_reconnect(self, config: ReconnectConfig) -> Self
Sourcepub fn set_verify_crc(&mut self, verify: bool)
pub fn set_verify_crc(&mut self, verify: bool)
Enable or disable CRC verification
Sourcepub fn verify_crc(&self) -> bool
pub fn verify_crc(&self) -> bool
Get current CRC verification setting
Sourcepub fn reconnect_count(&self) -> usize
pub fn reconnect_count(&self) -> usize
Get reconnection count
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if currently connected
Sourcepub async fn receive<T: Message>(&mut self) -> Result<IgtlMessage<T>>
pub async fn receive<T: Message>(&mut self) -> Result<IgtlMessage<T>>
Receive a message
Sourcepub async fn receive_any(&mut self) -> Result<AnyMessage>
pub async fn receive_any(&mut self) -> Result<AnyMessage>
Receive any message type dynamically without knowing the type in advance
This method reads the message header first, determines the message type, and then decodes the appropriate message type dynamically.
§Returns
An AnyMessage
enum containing the decoded message. If the message type
is not recognized, it will be returned as AnyMessage::Unknown
with the
raw header and body bytes.
§Examples
use openigtlink_rust::io::builder::ClientBuilder;
use openigtlink_rust::protocol::AnyMessage;
let mut client = ClientBuilder::new()
.tcp("127.0.0.1:18944")
.async_mode()
.build()
.await?;
loop {
let msg = client.receive_any().await?;
match msg {
AnyMessage::Transform(transform_msg) => {
println!("Received transform from {}",
transform_msg.header.device_name.as_str()?);
}
AnyMessage::Status(status_msg) => {
println!("Status: {}", status_msg.content.status_string);
}
AnyMessage::Image(image_msg) => {
println!("Received image: {}x{}x{}",
image_msg.content.size[0],
image_msg.content.size[1],
image_msg.content.size[2]);
}
AnyMessage::Unknown { header, .. } => {
println!("Unknown message type: {}",
header.type_name.as_str()?);
}
_ => {}
}
}
Auto Trait Implementations§
impl !Freeze for UnifiedAsyncClient
impl !RefUnwindSafe for UnifiedAsyncClient
impl Send for UnifiedAsyncClient
impl Sync for UnifiedAsyncClient
impl Unpin for UnifiedAsyncClient
impl !UnwindSafe for UnifiedAsyncClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more