Skip to main content

UdpLink

Struct UdpLink 

Source
pub struct UdpLink { /* private fields */ }
Expand description

A UDP socket presented as a ByteLink.

The peer is either learned from the first datagram received (in bind mode) or set up front (in connect mode), and every received datagram refreshes it, so a vehicle that moves ports is followed.

Implementations§

Source

pub async fn bind(local: impl ToSocketAddrs) -> Result<Self>

Binds a local address and learns the peer from the first datagram received.

Read before writing in this mode: a write before any datagram has arrived has no peer to send to. This suits a vehicle configured to send its telemetry to this port.

§Arguments
  • local - the local address to bind, such as "0.0.0.0:14550".
§Returns

The bound link, with no peer yet.

§Errors

Returns an io::Error if the address cannot be bound.

Source

pub async fn connect( local: impl ToSocketAddrs, remote: SocketAddr, ) -> Result<Self>

Binds a local address and sets a fixed peer to send to.

This suits talking to a vehicle at a known address, such as PX4’s offboard UDP port.

§Arguments
  • local - the local address to bind, such as "0.0.0.0:0".
  • remote - the vehicle’s address to send to.
§Returns

The link, ready to send.

§Errors

Returns an io::Error if the address cannot be bound.

Source

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

Returns the local address the socket is bound to.

§Returns

The bound local address.

§Errors

Returns an io::Error if the address cannot be read.

Source

pub fn peer(&self) -> Option<SocketAddr>

Returns the peer address, once one is known.

§Returns

The peer address, or None before any datagram has been received in bind mode.

Trait Implementations§

Source§

async fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Reads available bytes into buf, returning how many were read. Read more
Source§

async fn write_all(&mut self, data: &[u8]) -> Result<()>

Writes all of data to the link. 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.