pub struct NomadSocket { /* private fields */ }transport only.Expand description
Async UDP socket wrapper for NOMAD.
Provides convenient methods for sending/receiving frames with proper buffer management.
Implementations§
Source§impl NomadSocket
impl NomadSocket
Sourcepub async fn bind(addr: SocketAddr) -> Result<Self>
pub async fn bind(addr: SocketAddr) -> Result<Self>
Create a new NOMAD socket bound to the given address.
Sourcepub fn from_socket(socket: UdpSocket) -> Self
pub fn from_socket(socket: UdpSocket) -> Self
Create a NOMAD socket from an existing UDP socket.
Sourcepub fn set_max_payload_size(&mut self, size: usize)
pub fn set_max_payload_size(&mut self, size: usize)
Set the maximum payload size (for MTU considerations).
Sourcepub fn max_payload_size(&self) -> usize
pub fn max_payload_size(&self) -> usize
Get the maximum payload size.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Get the local address.
Sourcepub async fn connect(&self, addr: SocketAddr) -> Result<()>
pub async fn connect(&self, addr: SocketAddr) -> Result<()>
Connect to a remote address (for client sockets).
After connecting, send and recv can be used instead of
send_to and recv_from.
Sourcepub async fn send_to(&self, data: &[u8], addr: SocketAddr) -> Result<usize>
pub async fn send_to(&self, data: &[u8], addr: SocketAddr) -> Result<usize>
Send data to a specific address.
Sourcepub async fn recv_from(&mut self) -> Result<(&[u8], SocketAddr)>
pub async fn recv_from(&mut self) -> Result<(&[u8], SocketAddr)>
Receive data and return the sender’s address.
Sourcepub fn try_recv_from(&mut self) -> Result<Option<(usize, SocketAddr)>>
pub fn try_recv_from(&mut self) -> Result<Option<(usize, SocketAddr)>>
Try to receive data without blocking.
Returns Ok(None) if no data is available.
Sourcepub fn recv_data(&self, len: usize) -> &[u8] ⓘ
pub fn recv_data(&self, len: usize) -> &[u8] ⓘ
Get the received data after a successful try_recv_from.
Sourcepub fn socket_arc(&self) -> Arc<UdpSocket>
pub fn socket_arc(&self) -> Arc<UdpSocket>
Get a clone of the Arc-wrapped socket.
Sourcepub fn max_frame_size(&self) -> usize
pub fn max_frame_size(&self) -> usize
Calculate maximum frame size considering headers.