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::{IoService, Protocol, Endpoint}; use asyncio::ip::{Udp, UdpEndpoint, UdpSocket, IpAddrV4}; let io = &IoService::new(); let soc = UdpSocket::new(io, 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::{IoService, Protocol, Endpoint}; use asyncio::ip::{Udp, UdpEndpoint, UdpSocket, IpAddrV4}; use asyncio::socket_base::ReuseAddr; let io = &IoService::new(); let ep = UdpEndpoint::new(Udp::v4(), 12345); let soc = UdpSocket::new(io, 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();
Methods
impl Udp
[src]
fn v4() -> Udp
Represents a UDP for IPv4.
Examples
use asyncio::Endpoint; use asyncio::ip::{Udp, UdpEndpoint, IpAddrV4}; 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::{Udp, UdpEndpoint, IpAddrV6}; let ep = UdpEndpoint::new(IpAddrV6::any(), 0); assert_eq!(Udp::v6(), ep.protocol());
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 Debug for Udp
[src]
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.