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]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Eq for Udp
[src]

impl PartialEq for Udp
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Ord for Udp
[src]

This method returns an Ordering between self and other. Read more

impl PartialOrd for Udp
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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]

Reurns a value suitable for passing as the domain argument.

Returns a value suitable for passing as the type argument.

Returns a value suitable for passing as the protocol argument.

impl IpProtocol for Udp
[src]

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());

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());

impl Debug for Udp
[src]

Formats the value using the given formatter.