Struct nannou_osc::send::Sender

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

A type used for sending OSC packets.

Implementations§

source§

impl<M> Sender<M>

source

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

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

source§

impl Sender<Unconnected>

source

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

Creates a new Sender with the UDP socket bound to the given address. Note: this is not the target address, rather it is the address of the socket used by the Sender to send packets. Use the bind constructor instead if you would like the Sender’s socket bound to the default address.


use nannou_osc::Sender;

fn main() {
    let tx = Sender::bind_to("0.0.0.0:0").expect("Couldn't bind socket to the address");
}

The returned Sender is Unconnected, meaning that it is not currently connected to a specific target address. This means that the target address will have to be specified when calling send. To connect the Sender to a specific target address, use the connect builder method which will return a Sender in the Connected mode.

source

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

The same as bind_to but assumes the default_sender_socket_addr_v4 socket address.

source

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

Connects the Sender’s UDP socket to the given target, remote address.

The returned Sender will only send packets to the specified address.

Returns an error if some IO error occurred.

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


use nannou_osc::Sender;

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

pub fn send<P, A>( &self, packet: P, addr: A ) -> Result<usize, CommunicationError>
where P: Into<Packet>, A: ToSocketAddrs,

Sends the given packet on the Senders socket to the given address.

The given packet can be of any type that can be converted directly into a Packet. This includes Message, Bundle and (String, Vec<Type>) (which will be interpreted as a Message).

On success, returns the number of bytes written.

This will return a CommunicationError if:

  • The given packet fails to be encoded to bytes
  • The IP version of the local socket does not match that returned from addr or
  • The inner UdpSocket::send_to call fails.
source§

impl Sender<Connected>

source

pub fn remote_addr(&self) -> SocketAddr

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

source

pub fn send<P>(&self, packet: P) -> Result<usize, CommunicationError>
where P: Into<Packet>,

Sends the given packet on the Senders socket to the connected address.

On success, returns the number of bytes written.

This will return a CommunicationError if:

  • The given packet fails to be encoded to bytes
  • The IP version of the local socket does not match the connected socket or
  • The inner UdpSocket::send call fails.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<M> UnwindSafe for Sender<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.