Struct asyncio::ip::Udp
[−]
[src]
pub struct Udp { /* fields omitted */ }
The User Datagram Protocol.
Examples
In this example, Create a UDP client socket and send to an endpoint.
use asyncio::{IoContext, Protocol, Endpoint}; use asyncio::ip::{IpProtocol, IpAddrV4, Udp, UdpEndpoint, UdpSocket}; let ctx = &IoContext::new().unwrap(); let soc = UdpSocket::new(ctx, Udp::v4()).unwrap(); let ep = UdpEndpoint::new(IpAddrV4::loopback(), 12345); soc.send_to("hello".as_bytes(), 0, ep).unwrap();
Examples
In this example, Creates a UDP server and receive from an endpoint.
use asyncio::{IoContext, Protocol, Endpoint}; use asyncio::ip::{IpProtocol, IpAddrV4, Udp, UdpEndpoint, UdpSocket}; use asyncio::socket_base::ReuseAddr; let ctx = &IoContext::new().unwrap(); let ep = UdpEndpoint::new(Udp::v4(), 12345); let soc = UdpSocket::new(ctx, ep.protocol()).unwrap(); soc.set_option(ReuseAddr::new(true)).unwrap(); soc.bind(&ep).unwrap(); let mut buf = [0; 256]; let (len, ep) = soc.receive_from(&mut buf, 0).unwrap();
Trait Implementations
impl Clone for Udp
[src]
fn clone(&self) -> Udp
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Eq for Udp
[src]
impl PartialEq for Udp
[src]
fn eq(&self, __arg_0: &Udp) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Udp) -> bool
This method tests for !=
.
impl Ord for Udp
[src]
fn cmp(&self, __arg_0: &Udp) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl PartialOrd for Udp
[src]
fn partial_cmp(&self, __arg_0: &Udp) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Udp) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Udp) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Udp) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Udp) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Protocol for Udp
[src]
type Endpoint = IpEndpoint<Self>
fn family_type(&self) -> i32
Reurns a value suitable for passing as the domain argument.
fn socket_type(&self) -> i32
Returns a value suitable for passing as the type argument.
fn protocol_type(&self) -> i32
Returns a value suitable for passing as the protocol argument.
unsafe fn uninitialized(&self) -> Self::Endpoint
impl IpProtocol for Udp
[src]
fn v4() -> Udp
Represents a UDP for IPv4.
Examples
use asyncio::Endpoint; use asyncio::ip::{IpProtocol, IpAddrV4, Udp, UdpEndpoint}; let ep = UdpEndpoint::new(IpAddrV4::any(), 0); assert_eq!(Udp::v4(), ep.protocol());
fn v6() -> Udp
Represents a UDP for IPv6.
Examples
use asyncio::Endpoint; use asyncio::ip::{IpProtocol, IpAddrV6, Udp, UdpEndpoint}; let ep = UdpEndpoint::new(IpAddrV6::any(), 0); assert_eq!(Udp::v6(), ep.protocol());