8 releases

0.2.2 Oct 6, 2024
0.2.1 Oct 23, 2021
0.1.4 Jul 17, 2019
0.1.3 Dec 11, 2018
0.1.0 Dec 22, 2017

#597 in Network programming

Download history 279/week @ 2024-07-29 294/week @ 2024-08-05 256/week @ 2024-08-12 252/week @ 2024-08-19 214/week @ 2024-08-26 172/week @ 2024-09-02 165/week @ 2024-09-09 271/week @ 2024-09-16 253/week @ 2024-09-23 260/week @ 2024-09-30 185/week @ 2024-10-07 140/week @ 2024-10-14 135/week @ 2024-10-21 119/week @ 2024-10-28 80/week @ 2024-11-04 140/week @ 2024-11-11

486 downloads per month
Used in 5 crates

MIT license

36KB
642 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

~98KB