pub struct IgtlConnection { /* private fields */ }
Expand description
Represents an accepted client connection
Provides methods to send and receive OpenIGTLink messages over the connection.
Implementations§
Source§impl IgtlConnection
impl IgtlConnection
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
Sourcepub fn send<T: Message>(&mut self, msg: &IgtlMessage<T>) -> Result<()>
pub fn send<T: Message>(&mut self, msg: &IgtlMessage<T>) -> Result<()>
Send a message to the connected client
§Arguments
msg
- Message to send
§Errors
IgtlError::Io
- Network write failed (connection lost, broken pipe, etc.)IgtlError::BodyTooLarge
- Message exceeds maximum size
§Examples
use openigtlink_rust::io::IgtlServer;
use openigtlink_rust::protocol::types::StatusMessage;
use openigtlink_rust::protocol::message::IgtlMessage;
let server = IgtlServer::bind("127.0.0.1:18944")?;
let mut conn = server.accept()?;
let status = StatusMessage::ok("Ready");
let msg = IgtlMessage::new(status, "Server")?;
conn.send(&msg)?;
Sourcepub fn receive<T: Message>(&mut self) -> Result<IgtlMessage<T>>
pub fn receive<T: Message>(&mut self) -> Result<IgtlMessage<T>>
Receive a message from the connected client
Blocks until a complete message is received.
§Errors
IgtlError::Io
- Network read failed (connection lost, timeout, etc.)IgtlError::InvalidHeader
- Received malformed headerIgtlError::CrcMismatch
- Data corruption detectedIgtlError::UnknownMessageType
- Unsupported message typeIgtlError::InvalidSize
- Message size mismatch
§Examples
use openigtlink_rust::io::IgtlServer;
use openigtlink_rust::protocol::types::TransformMessage;
use openigtlink_rust::protocol::message::IgtlMessage;
let server = IgtlServer::bind("127.0.0.1:18944")?;
let mut conn = server.accept()?;
let msg: IgtlMessage<TransformMessage> = conn.receive()?;
Sourcepub fn receive_any(&mut self) -> Result<AnyMessage>
pub fn receive_any(&mut self) -> Result<AnyMessage>
Receive any message type dynamically
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::IgtlServer;
use openigtlink_rust::protocol::AnyMessage;
let server = IgtlServer::bind("127.0.0.1:18944")?;
let mut conn = server.accept()?;
let msg = conn.receive_any()?;
match msg {
AnyMessage::Transform(_) => println!("Received transform"),
AnyMessage::Status(_) => println!("Received status"),
_ => println!("Received other message"),
}
Sourcepub fn set_read_timeout(&mut self, timeout: Option<Duration>) -> Result<()>
pub fn set_read_timeout(&mut self, timeout: Option<Duration>) -> Result<()>
Set read timeout for the underlying TCP stream
§Arguments
timeout
- Timeout duration (None for infinite)
Sourcepub fn set_write_timeout(&mut self, timeout: Option<Duration>) -> Result<()>
pub fn set_write_timeout(&mut self, timeout: Option<Duration>) -> Result<()>
Set write timeout for the underlying TCP stream
§Arguments
timeout
- Timeout duration (None for infinite)
Sourcepub fn set_nodelay(&self, nodelay: bool) -> Result<()>
pub fn set_nodelay(&self, nodelay: bool) -> Result<()>
Enable or disable TCP_NODELAY (Nagle’s algorithm)
Wrapper around std::net::TcpStream::set_nodelay
.
Sourcepub fn set_recv_buffer_size(&self, size: usize) -> Result<()>
pub fn set_recv_buffer_size(&self, size: usize) -> Result<()>
Set the size of the TCP receive buffer (SO_RCVBUF)
Sourcepub fn set_send_buffer_size(&self, size: usize) -> Result<()>
pub fn set_send_buffer_size(&self, size: usize) -> Result<()>
Set the size of the TCP send buffer (SO_SNDBUF)
Sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Get the remote peer address
Auto Trait Implementations§
impl Freeze for IgtlConnection
impl RefUnwindSafe for IgtlConnection
impl Send for IgtlConnection
impl Sync for IgtlConnection
impl Unpin for IgtlConnection
impl UnwindSafe for IgtlConnection
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