8000 GitHub - d-rezzer/telnet-rs: A simple implementation of Telnet in Rust.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

d-rezzer/telnet-rs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

telnet-rs

Build Status MIT licensed crates.io API docs

A simple Telnet implementation.

Examples

Blocking Reading

extern crate telnet;

use telnet::{Telnet, TelnetEvent};

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

        match event {
            TelnetEvent::Data(buffer) => {
                // Debug: print the data buffer
                println!("{:?}", buffer);
                // process the data buffer
            },
            _ => {}
        }
    }
}

Non-Blocking Reading

extern crate telnet;

use telnet::{Telnet, TelnetEvent};

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

        match event {
            TelnetEvent::Data(buffer) => {
                // Debug: print the data buffer
                println!("{:?}", buffer);
                // process the data buffer
            },
            _ => {}
        }

        // Do something else ...
    }
}

Writing

extern crate telnet;

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

  • To reduce unnecessary data copy
  • To add coverage check
  • Add crate-level document

About

A simple implementation of Telnet in Rust.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%
0