Struct asyncio::ip::Tcp [] [src]

pub struct Tcp { /* fields omitted */ }

The Transmission Control Protocol.

Examples

In this example, Create a TCP server socket and accept a connection by client.

use asyncio::{IoContext, Protocol, Endpoint};
use asyncio::ip::{IpProtocol, Tcp, TcpEndpoint, TcpSocket, TcpListener};
use asyncio::socket_base::ReuseAddr;

let ctx = &IoContext::new().unwrap();
let ep = TcpEndpoint::new(Tcp::v4(), 12345);
let soc = TcpListener::new(ctx, ep.protocol()).unwrap();

soc.set_option(ReuseAddr::new(true)).unwrap();
soc.bind(&ep).unwrap();
soc.listen().unwrap();

let (acc, ep) = soc.accept().unwrap();

Examples

In this example, Create a TCP client socket and connect to TCP server.

use asyncio::{IoContext, Protocol, Endpoint};
use asyncio::ip::{IpProtocol, IpAddrV4, Tcp, TcpEndpoint, TcpSocket};

let ctx = &IoContext::new().unwrap();
let soc = TcpSocket::new(ctx, Tcp::v4()).unwrap();

let _ = soc.connect(&TcpEndpoint::new(IpAddrV4::loopback(), 12345));

Examples

In this example, Resolve a TCP hostname and connect to TCP server.

use asyncio::{IoContext, Protocol, Endpoint};
use asyncio::ip::{Tcp, TcpEndpoint, TcpSocket, TcpResolver};

let ctx = &IoContext::new().unwrap();
let re = TcpResolver::new(ctx);
let (soc, ep) = re.connect(("localhost", "12345")).unwrap();

Trait Implementations

impl Clone for Tcp
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Eq for Tcp
[src]

impl PartialEq for Tcp
[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 Tcp
[src]

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

impl PartialOrd for Tcp
[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 Tcp
[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 Tcp
[src]

Represents a TCP for IPv4.

Examples

use asyncio::Endpoint;
use asyncio::ip::{IpProtocol, IpAddrV4, Tcp, TcpEndpoint};

let ep = TcpEndpoint::new(IpAddrV4::any(), 0);
assert_eq!(Tcp::v4(), ep.protocol());

Represents a TCP for IPv6.

Examples

use asyncio::Endpoint;
use asyncio::ip::{IpProtocol, IpAddrV6, Tcp, TcpEndpoint};

let ep = TcpEndpoint::new(IpAddrV6::any(), 0);
assert_eq!(Tcp::v6(), ep.protocol());

impl Debug for Tcp
[src]

Formats the value using the given formatter.