pub struct AsyncIgtlClient { /* private fields */ }๐Deprecated since 0.2.0: Use ClientBuilder instead: ClientBuilder::new().tcp(addr).async_mode().build().await
Expand description
Asynchronous OpenIGTLink client
Uses non-blocking I/O with Tokio for high-concurrency scenarios.
ยงExamples
use openigtlink_rust::io::AsyncIgtlClient;
use openigtlink_rust::protocol::types::StatusMessage;
use openigtlink_rust::protocol::message::IgtlMessage;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = AsyncIgtlClient::connect("127.0.0.1:18944").await?;
let status = StatusMessage::ok("Hello");
let msg = IgtlMessage::new(status, "AsyncClient")?;
client.send(&msg).await?;
Ok(())
}Implementationsยง
Sourceยงimpl AsyncIgtlClient
impl AsyncIgtlClient
Sourcepub async fn connect(addr: &str) -> Result<Self>
pub async fn connect(addr: &str) -> Result<Self>
Connect to an OpenIGTLink server asynchronously
ยงArguments
addr- Server address (e.g., โ127.0.0.1:18944โ)
ยงErrors
IgtlError::Io- Failed to connect
ยงExamples
use openigtlink_rust::io::AsyncIgtlClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AsyncIgtlClient::connect("127.0.0.1:18944").await?;
Ok(())
}Sourcepub fn set_verify_crc(&mut self, verify: bool)
pub fn set_verify_crc(&mut self, verify: bool)
Sourcepub fn verify_crc(&self) -> bool
pub fn verify_crc(&self) -> bool
Get current CRC verification setting
Sourcepub async fn send<T: Message>(&mut self, msg: &IgtlMessage<T>) -> Result<()>
pub async fn send<T: Message>(&mut self, msg: &IgtlMessage<T>) -> Result<()>
Send a message to the server asynchronously
ยงArguments
msg- Message to send
ยงErrors
IgtlError::Io- Network write failedIgtlError::BodyTooLarge- Message exceeds maximum size
ยงExamples
use openigtlink_rust::io::AsyncIgtlClient;
use openigtlink_rust::protocol::types::StatusMessage;
use openigtlink_rust::protocol::message::IgtlMessage;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = AsyncIgtlClient::connect("127.0.0.1:18944").await?;
let status = StatusMessage::ok("Ready");
let msg = IgtlMessage::new(status, "Client")?;
client.send(&msg).await?;
Ok(())
}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 from the server asynchronously
ยงErrors
IgtlError::Io- Network read failedIgtlError::InvalidHeader- Received malformed headerIgtlError::CrcMismatch- Data corruption detectedIgtlError::UnknownMessageType- Unsupported message type
ยงExamples
use openigtlink_rust::io::AsyncIgtlClient;
use openigtlink_rust::protocol::types::TransformMessage;
use openigtlink_rust::protocol::message::IgtlMessage;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = AsyncIgtlClient::connect("127.0.0.1:18944").await?;
let msg: IgtlMessage<TransformMessage> = client.receive().await?;
Ok(())
}Sourcepub async fn set_read_timeout(
&mut self,
timeout: Option<Duration>,
) -> Result<()>
pub async fn set_read_timeout( &mut self, timeout: Option<Duration>, ) -> Result<()>
Set read timeout for the underlying TCP stream
Sourcepub async fn set_write_timeout(
&mut self,
timeout: Option<Duration>,
) -> Result<()>
pub async fn set_write_timeout( &mut self, timeout: Option<Duration>, ) -> Result<()>
Set write timeout for the underlying TCP stream
Sourcepub async fn set_nodelay(&self, nodelay: bool) -> Result<()>
pub async fn set_nodelay(&self, nodelay: bool) -> Result<()>
Enable or disable TCP_NODELAY (Nagleโs algorithm)
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Get the local address
Sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Get the remote peer address
Sourcepub fn into_split(self) -> (AsyncIgtlReader, AsyncIgtlWriter)
pub fn into_split(self) -> (AsyncIgtlReader, AsyncIgtlWriter)
Split the client into read and write halves
This allows concurrent reading and writing on separate tasks.
ยงExamples
use openigtlink_rust::io::AsyncIgtlClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AsyncIgtlClient::connect("127.0.0.1:18944").await?;
let (reader, writer) = client.into_split();
// Use reader and writer in separate tasks
Ok(())
}Auto Trait Implementationsยง
impl !Freeze for AsyncIgtlClient
impl RefUnwindSafe for AsyncIgtlClient
impl Send for AsyncIgtlClient
impl Sync for AsyncIgtlClient
impl Unpin for AsyncIgtlClient
impl UnwindSafe for AsyncIgtlClient
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