pub struct AsyncIgtlConnection { /* private fields */ }
Expand description
Represents an accepted client connection (async)
Provides methods to send and receive OpenIGTLink messages asynchronously.
Implementations§
Source§impl AsyncIgtlConnection
impl AsyncIgtlConnection
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 connected client asynchronously
§Arguments
msg
- Message to send
§Errors
IgtlError::Io
- Network write failedIgtlError::BodyTooLarge
- Message exceeds maximum size
§Examples
use openigtlink_rust::io::AsyncIgtlServer;
use openigtlink_rust::protocol::types::StatusMessage;
use openigtlink_rust::protocol::message::IgtlMessage;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server = AsyncIgtlServer::bind("127.0.0.1:18944").await?;
let mut conn = server.accept().await?;
let status = StatusMessage::ok("Ready");
let msg = IgtlMessage::new(status, "Server")?;
conn.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 connected client asynchronously
§Errors
IgtlError::Io
- Network read failedIgtlError::InvalidHeader
- Received malformed headerIgtlError::CrcMismatch
- Data corruption detectedIgtlError::UnknownMessageType
- Unsupported message type
§Examples
use openigtlink_rust::io::AsyncIgtlServer;
use openigtlink_rust::protocol::types::TransformMessage;
use openigtlink_rust::protocol::message::IgtlMessage;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server = AsyncIgtlServer::bind("127.0.0.1:18944").await?;
let mut conn = server.accept().await?;
let msg: IgtlMessage<TransformMessage> = conn.receive().await?;
Ok(())
}
Sourcepub async fn receive_any(&mut self) -> Result<AnyMessage>
pub async fn receive_any(&mut self) -> Result<AnyMessage>
Receive any message type dynamically (async)
This method receives a message without knowing its type in advance,
returning it as an AnyMessage
enum that can be pattern matched.
§Errors
IgtlError::Io
- Network read failedIgtlError::InvalidHeader
- Malformed headerIgtlError::CrcMismatch
- Data corruption detected
§Examples
use openigtlink_rust::io::AsyncIgtlServer;
use openigtlink_rust::protocol::AnyMessage;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server = AsyncIgtlServer::bind("127.0.0.1:18944").await?;
let mut conn = server.accept().await?;
let msg = conn.receive_any().await?;
match msg {
AnyMessage::Transform(_) => println!("Received transform"),
AnyMessage::Status(_) => println!("Received status"),
_ => println!("Received other message"),
}
Ok(())
}
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 peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Get the remote peer address
Sourcepub fn into_split(
self,
) -> (AsyncIgtlConnectionReader, AsyncIgtlConnectionWriter)
pub fn into_split( self, ) -> (AsyncIgtlConnectionReader, AsyncIgtlConnectionWriter)
Split the connection into read and write halves
This allows concurrent reading and writing on separate tasks.
Auto Trait Implementations§
impl !Freeze for AsyncIgtlConnection
impl RefUnwindSafe for AsyncIgtlConnection
impl Send for AsyncIgtlConnection
impl Sync for AsyncIgtlConnection
impl Unpin for AsyncIgtlConnection
impl UnwindSafe for AsyncIgtlConnection
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