pub struct Tcp { /* private fields */ }
Expand description
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§
Source§impl GetSocketOption<Tcp> for NoDelay
impl GetSocketOption<Tcp> for NoDelay
Source§impl IpProtocol for Tcp
impl IpProtocol for Tcp
Source§fn v4() -> Tcp
fn v4() -> Tcp
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());
Source§fn v6() -> Tcp
fn v6() -> Tcp
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());
fn is_v4(&self) -> bool
fn is_v6(&self) -> bool
Source§impl Ord for Tcp
impl Ord for Tcp
Source§impl PartialOrd for Tcp
impl PartialOrd for Tcp
Source§impl Protocol for Tcp
impl Protocol for Tcp
type Endpoint = IpEndpoint<Tcp>
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
Source§impl SetSocketOption<Tcp> for NoDelay
impl SetSocketOption<Tcp> for NoDelay
Source§impl SocketOption<Tcp> for NoDelay
impl SocketOption<Tcp> for NoDelay
impl Eq for Tcp
impl StructuralPartialEq for Tcp
Auto Trait Implementations§
impl Freeze for Tcp
impl RefUnwindSafe for Tcp
impl Send for Tcp
impl Sync for Tcp
impl Unpin for Tcp
impl UnwindSafe for Tcp
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