7 releases

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

#1547 in Network programming

Download history 146/week @ 2023-11-20 85/week @ 2023-11-27 269/week @ 2023-12-04 61/week @ 2023-12-11 66/week @ 2023-12-18 32/week @ 2023-12-25 76/week @ 2024-01-01 59/week @ 2024-01-08 100/week @ 2024-01-15 73/week @ 2024-01-22 50/week @ 2024-01-29 104/week @ 2024-02-05 65/week @ 2024-02-12 116/week @ 2024-02-19 182/week @ 2024-02-26 360/week @ 2024-03-04

731 downloads per month
Used in 4 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

~95KB