Struct nannou::osc::recv::Receiver
[−]
[src]
pub struct Receiver<M = Unconnected> { /* fields omitted */ }
A type used for receiving OSC packets.
Methods
impl<M> Receiver<M>
[src]
pub fn local_addr(&self) -> Result<SocketAddr, Error>
[src]
The socket address that this Receiver
's socket was created from.
impl Receiver<Unconnected>
[src]
pub fn bind_to<A>(addr: A) -> Result<Self, Error> where
A: ToSocketAddrs,
[src]
A: ToSocketAddrs,
Create a Receiver
that listen for OSC packets on the given address.
extern crate nannou; use nannou::osc::Receiver; fn main() { let rx = Receiver::bind_to("127.0.0.1:34254").expect("Couldn't bind socket to address"); }
pub fn bind_to_with_mtu<A>(addr: A, mtu: usize) -> Result<Self, Error> where
A: ToSocketAddrs,
[src]
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
.
extern crate nannou; 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"); }
pub fn bind(port: u16) -> Result<Self, Error>
[src]
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>
.
extern crate nannou; use nannou::osc::Receiver; fn main() { let rx = Receiver::bind(34254).expect("Couldn't bind socket to default address"); }
pub fn bind_with_mtu(port: u16, mtu: usize) -> Result<Self, Error>
[src]
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>
.
extern crate nannou; 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"); }
pub fn connect<A>(self, addr: A) -> Result<Receiver<Connected>, Error> where
A: ToSocketAddrs,
[src]
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
.
extern crate nannou; 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"); }
pub fn recv(&self) -> Result<(Packet, SocketAddr), CommunicationError>
[src]
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
.
pub fn try_recv(
&self
) -> Result<Option<(Packet, SocketAddr)>, CommunicationError>
[src]
&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)
.
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
.
pub fn iter(&self) -> Iter<Unconnected>
[src]
An iterator yielding OSC Packet
s along with their source address.
Each call to next
will block until the next packet is received or until some error
occurs.
pub fn try_iter(&self) -> TryIter<Unconnected>
[src]
An iterator yielding OSC Packet
s along with their source address.
Each call to next
will only return Some
while there are pending packets and will return
None
otherwise.
impl Receiver<Connected>
[src]
pub fn remote_addr(&self) -> SocketAddr
[src]
Returns the address of the socket to which the Receiver
is Connected
.
pub fn recv(&self) -> Result<Packet, CommunicationError>
[src]
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
.
pub fn try_recv(&self) -> Result<Option<Packet>, CommunicationError>
[src]
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
.
pub fn iter(&self) -> Iter<Connected>
[src]
An iterator yielding OSC Packet
s.
Each call to next
will block until the next packet is received or until some error
occurs.
pub fn try_iter(&self) -> TryIter<Connected>
[src]
An iterator yielding OSC Packet
s.
Each call to next
will only return Some
while there are pending packets and will return
None
otherwise.