63 releases

new 0.26.0 May 19, 2023
0.24.4 May 29, 2022
0.24.3 Feb 11, 2022
0.24.0 Dec 30, 2021
0.4.1 Jun 26, 2019

#676 in Network programming

Download history 13614/week @ 2023-01-27 14381/week @ 2023-02-03 13592/week @ 2023-02-10 13834/week @ 2023-02-17 13428/week @ 2023-02-24 11791/week @ 2023-03-03 14144/week @ 2023-03-10 13011/week @ 2023-03-17 12927/week @ 2023-03-24 13150/week @ 2023-03-31 11423/week @ 2023-04-07 14249/week @ 2023-04-14 14485/week @ 2023-04-21 14191/week @ 2023-04-28 15757/week @ 2023-05-05 12346/week @ 2023-05-12

59,127 downloads per month
Used in 65 crates (via amq-protocol-tcp)

BSD-2-Clause

31KB
605 lines

std::net::TcpStream on steroids

API Docs Build status Downloads

tcp-stream is a library aiming at providing TLS support to std::net::TcpStream

Examples

To connect to a remote server:

use tcp_stream::{HandshakeError, TcpStream, TLSConfig};

use std::io::{self, Read, Write};

fn main() {
    let stream = TcpStream::connect("google.com:443").unwrap();
    let mut stream = stream.into_tls("google.com", TLSConfig::default());

    while let Err(HandshakeError::WouldBlock(mid_handshake)) = stream {
        stream = mid_handshake.handshake();
    }

    let mut stream = stream.unwrap();

    while let Err(err) = stream.write_all(b"GET / HTTP/1.0\r\n\r\n") {
        if err.kind() != io::ErrorKind::WouldBlock {
            panic!("error: {:?}", err);
        }
    }
    stream.flush().unwrap();
    let mut res = vec![];
    while let Err(err) = stream.read_to_end(&mut res) {
        if err.kind() != io::ErrorKind::WouldBlock {
            panic!("stream error: {:?}", err);
        }
    }
    println!("{}", String::from_utf8_lossy(&res));
}

Dependencies

~0–8MB
~139K SLoC