liveBook · Manning

TCP client

As explained in Rust Servers, Services, and Apps

A TCP client is a network participant that establishes a connection to a TCP server and exchanges byte-stream data.

A TCP client connects to a TCP server and exchanges a continuous stream of bytes. In Rust, TcpStream provides the client-side connection, while Read and Write handle data transfer. section 2.2.1 section 2.4

Build a minimal client in an incremental TCP workspace:

Echo client

A client connects to localhost:3000, writes "Hello" as bytes, reads five response bytes, and prints the returned text. The paired server echoes the same buffer, producing Got response from server:"Hello". section 2.2.2

Listing 2.3 tcpclient/src/main.rs
use std::net::TcpStream;
 
fn main() {
    let _stream = TcpStream::connect("localhost:3000").unwrap();    #1
}

Use the minimal client listing to see the connection-only implementation before adding byte exchange. section 2.2.2

How Rust Servers, Services, and Apps covers it

How deep it goes
Explains connection and byte I/O through Rust implementation, then stops short of interpreting application messages such as HTTP.
Examples
Uses a Cargo workspace, localhost:3000, TcpStream, byte buffers, and a Hello echo exchange.
What it assumes
Introduces client networking with Rust standard-library primitives rather than relying on external crates or prebuilt abstractions.
What you can do after
Builds a basic TCP client that connects, sends bytes, reads a response, and displays decoded data.
How it connects
Connects TCP clients with TCP servers, TCP/IP layers, byte streams, HTTP, and Rust standard-library networking.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.