NomadSocket

Struct NomadSocket 

Source
pub struct NomadSocket { /* private fields */ }
Available on crate feature 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

Source

pub async fn bind(addr: SocketAddr) -> Result<Self>

Create a new NOMAD socket bound to the given address.

Source

pub fn from_socket(socket: UdpSocket) -> Self

Create a NOMAD socket from an existing UDP socket.

Source

pub fn set_max_payload_size(&mut self, size: usize)

Set the maximum payload size (for MTU considerations).

Source

pub fn max_payload_size(&self) -> usize

Get the maximum payload size.

Source

pub fn local_addr(&self) -> Result<SocketAddr>

Get the local address.

Source

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.

Source

pub async fn send_to(&self, data: &[u8], addr: SocketAddr) -> Result<usize>

Send data to a specific address.

Source

pub async fn send(&self, data: &[u8]) -> Result<usize>

Send data to the connected address.

Source

pub async fn recv_from(&mut self) -> Result<(&[u8], SocketAddr)>

Receive data and return the sender’s address.

Source

pub async fn recv(&mut self) -> Result<&[u8]>

Receive data from the connected address.

Source

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.

Source

pub fn recv_data(&self, len: usize) -> &[u8]

Get the received data after a successful try_recv_from.

Source

pub fn inner(&self) -> &UdpSocket

Get a reference to the underlying socket.

Source

pub fn socket_arc(&self) -> Arc<UdpSocket>

Get a clone of the Arc-wrapped socket.

Source

pub fn max_frame_size(&self) -> usize

Calculate maximum frame size considering headers.

Trait Implementations§

Source§

impl Debug for NomadSocket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V