Struct std::net::TcpStreamUnstable [-] [+] [src]

pub struct TcpStream(_);

A structure which represents a TCP stream between a local socket and a remote socket.

The socket will be closed when the value is dropped.

Example

fn main() { use std::io::prelude::*; use std::net::TcpStream; { let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap(); // ignore the Result let _ = stream.write(&[1]); let _ = stream.read(&mut [0; 128]); // ignore here too } // the stream is closed here }
use std::io::prelude::*;
use std::net::TcpStream;

{
    let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap();

    // ignore the Result
    let _ = stream.write(&[1]);
    let _ = stream.read(&mut [0; 128]); // ignore here too
} // the stream is closed here

Methods

impl TcpStream

fn connect<A: ToSocketAddrs + ?Sized>(addr: &A) -> Result<TcpStream>

Open 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.

fn peer_addr(&self) -> Result<SocketAddr>

Returns the socket address of the remote peer of this TCP connection.

fn socket_addr(&self) -> Result<SocketAddr>

Returns the socket address of the local half of this TCP connection.

fn shutdown(&self, how: Shutdown) -> Result<()>

Shut down the read, write, or both halves of this connection.

This function will cause all pending and future I/O on the specified portions to return immediately with an appropriate value (see the documentation of Shutdown).

fn try_clone(&self) -> Result<TcpStream>

Create a new independently owned handle to the underlying socket.

The returned TcpStream is a reference to the same stream that this object references. Both handles will read and write the same stream of data, and options set on one stream will be propagated to the other stream.

fn set_nodelay(&self, nodelay: bool) -> Result<()>

Sets the nodelay flag on this connection to the boolean specified

fn set_keepalive(&self, seconds: Option<u32>) -> Result<()>

Sets the keepalive timeout to the timeout specified.

If the value specified is None, then the keepalive flag is cleared on this connection. Otherwise, the keepalive timeout will be set to the specified time, in seconds.

Trait Implementations

impl Read for TcpStream

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<()>

fn read_to_string(&mut self, buf: &mut String) -> Result<()>

impl Write for TcpStream

fn write(&mut self, buf: &[u8]) -> Result<usize>

fn flush(&mut self) -> Result<()>

fn write_all(&mut self, buf: &[u8]) -> Result<()>

fn write_fmt(&mut self, fmt: Arguments) -> Result<()>

impl AsRawFd for TcpStream

fn as_raw_fd(&self) -> Fd

impl AsRawFd for TcpStream

fn as_raw_fd(&self) -> Fd