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]

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

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]

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 Debug for Udp
[src]

Formats the value using the given formatter.

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]

Returns true if the protocol associated IP-v4 address.

Returns true if the protocol associated IP-v6 address.

Returns a IP-v4 protocol.

Returns a IP-v6 protocol.