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::{IoService, Protocol, Endpoint};
use asyncio::ip::{Tcp, TcpEndpoint, TcpSocket, TcpListener};
use asyncio::socket_base::ReuseAddr;

let io = &IoService::new();
let ep = TcpEndpoint::new(Tcp::v4(), 12345);
let soc = TcpListener::new(io, 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::{IoService, Protocol, Endpoint};
use asyncio::ip::{Tcp, TcpEndpoint, TcpSocket, IpAddrV4};

let io = &IoService::new();
let soc = TcpSocket::new(io, 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::{IoService, Protocol, Endpoint};
use asyncio::ip::{Tcp, TcpEndpoint, TcpSocket, TcpResolver};

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

Methods

impl Tcp
[src]

Represents a TCP for IPv4.

Examples

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

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::{Tcp, TcpEndpoint, IpAddrV6};

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

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

Formats the value using the given formatter.

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]

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.