pub struct TcpStream(/* private fields */);
Available on crate feature
net
only.Expand description
A TCP stream between a local and a remote socket.
Implementations§
source§impl TcpStream
impl TcpStream
sourcepub fn connect<A: ToSocketAddrs>(addr: A) -> Result<TcpStream>
pub fn connect<A: ToSocketAddrs>(addr: A) -> Result<TcpStream>
Opens a TCP connection to a remote host.
addr
is an address of the remote host. Anything which implements
ToSocketAddrs
trait can be supplied for the address; see this trait
documentation for concrete examples.
If addr
yields multiple addresses, connect
will be attempted with
each of the addresses until a connection is successful. If none of
the addresses result in a successful connection, the error returned from
the last connection attempt (the last address) is returned.
sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the socket address of the local half of this TCP connection.
sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Returns the socket address of the remote peer of this TCP connection.
Trait Implementations§
source§impl Read for TcpStream
impl Read for TcpStream
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning
how many bytes were read.
source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, AxError>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, AxError>
Available on crate feature
alloc
only.Read all bytes until EOF in this source, placing them into
buf
.source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, AxError>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, AxError>
Available on crate feature
alloc
only.Read all bytes until EOF in this source, appending them to
buf
.source§impl Write for TcpStream
impl Write for TcpStream
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written.
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered
contents reach their destination.
Auto Trait Implementations§
impl !RefUnwindSafe for TcpStream
impl Send for TcpStream
impl Sync for TcpStream
impl Unpin for TcpStream
impl UnwindSafe for TcpStream
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