7 个版本

0.2.1 2021 年 10 月 23 日
0.2.0 2021 年 10 月 6 日
0.1.4 2019 年 7 月 17 日
0.1.3 2018 年 12 月 11 日
0.1.0 2017 年 12 月 22 日

#7#expect

Download history 203/week @ 2024-03-13 169/week @ 2024-03-20 132/week @ 2024-03-27 183/week @ 2024-04-03 272/week @ 2024-04-10 190/week @ 2024-04-17 187/week @ 2024-04-24 142/week @ 2024-05-01 237/week @ 2024-05-08 344/week @ 2024-05-15 287/week @ 2024-05-22 189/week @ 2024-05-29 187/week @ 2024-06-05 184/week @ 2024-06-12 205/week @ 2024-06-19 198/week @ 2024-06-26

794 次每月下载
用于 4 crates

MIT 许可证

36KB
642

telnet-rs

Build Status MIT licensed crates.io API docs

简单的 Telnet 实现。

示例

阻塞读取

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
        }
    }
}

非阻塞读取

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 ...
    }
}

写入

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");
}

待办事项

  • 减少不必要的数据复制
  • 添加覆盖率检查
  • 添加 crate 级文档

依赖

~97KB