Struct nannou_osc::recv::Receiver

source ·
pub struct Receiver<M = Unconnected> { /* private fields */ }
Expand description

A type used for receiving OSC packets.

Implementations§

source§

impl<M> Receiver<M>

source

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

The socket address that this Receiver’s socket was created from.

source§

impl Receiver<Unconnected>

source

pub fn bind_to<A>(addr: A) -> Result<Self, Error>
where A: ToSocketAddrs,

Create a Receiver that listen for OSC packets on the given address.

use nannou_osc::Receiver;

fn main() {
    let rx = Receiver::bind_to("127.0.0.1:34254").expect("Couldn't bind socket to address");
}
source

pub fn bind_to_with_mtu<A>(addr: A, mtu: usize) -> Result<Self, Error>
where A: ToSocketAddrs,

The same as bind_to, but allows for manually specifying the MTU (aka “maximum transition unit”).

The MTU is the maximum UDP packet size in bytes that the Receiver’s UDP socket will receive before returning an error.

By default this is DEFAULT_MTU.

use nannou_osc::Receiver;

fn main() {
    let rx = Receiver::bind_to_with_mtu("127.0.0.1:34254", 60_000)
        .expect("Couldn't bind socket to address");
}
source

pub fn bind(port: u16) -> Result<Self, Error>

The same as bind_to, but assumes that the IP address is 0.0.0.0.

The resulting socket address will be 0.0.0.0:<port>.

use nannou_osc::Receiver;

fn main() {
    let rx = Receiver::bind(34254).expect("Couldn't bind socket to default address");
}
source

pub fn bind_with_mtu(port: u16, mtu: usize) -> Result<Self, Error>

The same as bind_to_with_mtu, but assumes that the IP address is 0.0.0.0.

The resulting socket address will be 0.0.0.0:<port>.

use nannou_osc::Receiver;

fn main() {
    let port = 34254;
    let mtu = 60_000;
    let rx = Receiver::bind_with_mtu(port, mtu).expect("Couldn't bind to default address");
}
source

pub fn connect<A>(self, addr: A) -> Result<Receiver<Connected>, Error>
where A: ToSocketAddrs,

Connects the Receiver’s UDP socket to the given remote address.

This applies filters so that only data from the given address is received.

**Panic!**s if the given addr cannot resolve to a valid SocketAddr.

use nannou_osc::Receiver;

fn main() {
    let tx = Receiver::bind(34254)
        .expect("Couldn't bind to default socket")
        .connect("127.0.0.1:34255")
        .expect("Couldn't connect to socket at address");
}
source

pub fn recv(&self) -> Result<(Packet, SocketAddr), CommunicationError>

Waits for the next OSC packet to be received and returns it along with the source address.

If the socket is currently in non-blocking mode, this method will first switch the socket to blocking.

This will return a CommunicationError if:

  • Switching the socket from “non_blocking” to “blocking” fails,
  • The Mutex around the inner buffer (used to collect bytes) was poisoned,
  • The MTU was not large enough to receive a UDP packet,
  • The inner UdpSocket::recv call fails or
  • The socket received some bytes that could not be decoded into an OSC Packet.
source

pub fn try_recv( &self ) -> Result<Option<(Packet, SocketAddr)>, CommunicationError>

Checks for a pending OSC packet and returns Ok(Some) if there is one waiting along with the source address.

If there are no packets waiting (or if the inner UDP socket’s recv method returns an error) this will immediately return with Ok(None).

When called, this method will pop a message from the receiver’s queue.

If the socket is currently in blocking mode, this method will first switch the socket to non-blocking.

This will return a CommunicationError if:

  • Switching the socket from “blocking” to “non_blocking” fails,
  • The Mutex around the inner buffer (used to collect bytes) was poisoned,
  • The socket received some bytes that could not be decoded into an OSC Packet.
source

pub fn iter(&self) -> Iter<'_, Unconnected>

An iterator yielding OSC Packets along with their source address.

Each call to next will block until the next packet is received or until some error occurs.

source

pub fn try_iter(&self) -> TryIter<'_, Unconnected>

An iterator yielding OSC Packets along with their source address.

Each call to next will only return Some while there are pending packets and will return None otherwise.

source§

impl Receiver<Connected>

source

pub fn remote_addr(&self) -> SocketAddr

Returns the address of the socket to which the Receiver is Connected.

source

pub fn recv(&self) -> Result<Packet, CommunicationError>

Waits for the next OSC packet to be received and returns it.

If the socket is currently in non-blocking mode, this method will first switch the socket to blocking.

This will return a CommunicationError if:

  • Switching the socket from “non_blocking” to “blocking” fails,
  • The Mutex around the inner buffer (used to collect bytes) was poisoned,
  • The MTU was not large enough to receive a UDP packet,
  • The inner UdpSocket::recv call fails or
  • The socket received some bytes that could not be decoded into an OSC Packet.
source

pub fn try_recv(&self) -> Result<Option<Packet>, CommunicationError>

Checks for a pending OSC packet and returns Ok(Some) if there is one waiting.

If there are no packets waiting (or if the inner UDP socket’s recv method returns an error) this will immediately return with Ok(None).

If the socket is currently in blocking mode, this method will first switch the socket to non-blocking.

This will return a CommunicationError if:

  • Switching the socket from “blocking” to “non_blocking” fails,
  • The Mutex around the inner buffer (used to collect bytes) was poisoned,
  • The socket received some bytes that could not be decoded into an OSC Packet.
source

pub fn iter(&self) -> Iter<'_, Connected>

An iterator yielding OSC Packets.

Each call to next will block until the next packet is received or until some error occurs.

source

pub fn try_iter(&self) -> TryIter<'_, Connected>

An iterator yielding OSC Packets.

Each call to next will only return Some while there are pending packets and will return None otherwise.

Auto Trait Implementations§

§

impl<M> RefUnwindSafe for Receiver<M>
where M: RefUnwindSafe,

§

impl<M> Send for Receiver<M>
where M: Send,

§

impl<M> Sync for Receiver<M>
where M: Sync,

§

impl<M> Unpin for Receiver<M>
where M: Unpin,

§

impl<M> UnwindSafe for Receiver<M>
where M: UnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.