9 releases

new 0.2.3 Feb 14, 2025
0.2.2 Oct 6, 2024
0.2.1 Oct 23, 2021
0.1.4 Jul 17, 2019
0.1.0 Dec 22, 2017

#558 in Network programming

Download history 114/week @ 2024-10-29 90/week @ 2024-11-05 146/week @ 2024-11-12 219/week @ 2024-11-19 241/week @ 2024-11-26 252/week @ 2024-12-03 413/week @ 2024-12-10 161/week @ 2024-12-17 60/week @ 2024-12-24 112/week @ 2024-12-31 252/week @ 2025-01-07 362/week @ 2025-01-14 327/week @ 2025-01-21 332/week @ 2025-01-28 739/week @ 2025-02-04 737/week @ 2025-02-11

2,260 downloads per month
Used in 5 crates

MIT license

51KB
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

~100KB