Zylatis / telnet-rs

A simple implementation of Telnet in Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

A simple implementation of Telnet in Rust.

License:MIT License


Languages

Language:Rust 99.0%Language:Shell 1.0%