10 releases

new 0.2.4 May 1, 2025
0.2.3 Feb 14, 2025
0.2.2 Oct 6, 2024
0.2.1 Oct 23, 2021
0.1.0 Dec 22, 2017

#236 in Network programming

Download history 277/week @ 2025-01-13 419/week @ 2025-01-20 252/week @ 2025-01-27 700/week @ 2025-02-03 731/week @ 2025-02-10 711/week @ 2025-02-17 397/week @ 2025-02-24 325/week @ 2025-03-03 413/week @ 2025-03-10 265/week @ 2025-03-17 312/week @ 2025-03-24 300/week @ 2025-03-31 413/week @ 2025-04-07 264/week @ 2025-04-14 323/week @ 2025-04-21 396/week @ 2025-04-28

1,420 downloads per month
Used in 5 crates

MIT license

49KB
643 lines

telnet-rs

Build Status MIT licensed crates.io API docs

A simple Telnet implementation.

Examples

Blocking Reading

use telnet::{Telnet, Event};

fn main() {
    let mut telnet = Telnet::connect(("ptt.cc", 23), 256)
            .expect("Couldn't connect to the server...");

    loop {
        let event = telnet.read().expect("Read error");

        if let Event::Data(buffer) = event {
            // Debug: print the data buffer
            println!("{:?}", buffer);
            // process the data buffer
        }
    }
}

Non-Blocking Reading

use telnet::{Telnet, Event};

fn main() {
    let mut telnet = Telnet::connect(("ptt.cc", 23), 256)
            .expect("Couldn't connect to the server...");

    loop {
        let event = telnet.read_nonblocking().expect("Read error");

        if let Event::Data(buffer) = event {
            // Debug: print the data buffer
            println!("{:?}", buffer);
            // process the data buffer
        }

        // Do something else ...
    }
}

Writing

use telnet::Telnet;

fn main() {
    let mut telnet = Telnet::connect(("ptt.cc", 23), 256)
            .expect("Couldn't connect to the server...");

    let buffer: [u8; 4] = [83, 76, 77, 84];
    telnet.write(&buffer).expect("Read error");
}

TODOs

  • reduce unnecessary data copy
  • add coverage check
  • add crate-level documentation

Dependencies

~105KB