pub struct Udp { /* private fields */ }
Expand description
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§
Source§impl IpProtocol for Udp
impl IpProtocol for Udp
Source§fn v4() -> Udp
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());
Source§fn v6() -> Udp
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());
fn is_v4(&self) -> bool
fn is_v6(&self) -> bool
Source§impl Ord for Udp
impl Ord for Udp
Source§impl PartialOrd for Udp
impl PartialOrd for Udp
Source§impl Protocol for Udp
impl Protocol for Udp
type Endpoint = IpEndpoint<Udp>
Source§fn family_type(&self) -> i32
fn family_type(&self) -> i32
Reurns a value suitable for passing as the domain argument.
Source§fn socket_type(&self) -> i32
fn socket_type(&self) -> i32
Returns a value suitable for passing as the type argument.
Source§fn protocol_type(&self) -> i32
fn protocol_type(&self) -> i32
Returns a value suitable for passing as the protocol argument.
unsafe fn uninitialized(&self) -> Self::Endpoint
impl Eq for Udp
impl StructuralPartialEq for Udp
Auto Trait Implementations§
impl Freeze for Udp
impl RefUnwindSafe for Udp
impl Send for Udp
impl Sync for Udp
impl Unpin for Udp
impl UnwindSafe for Udp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more