[][src]Struct telnet::Telnet

pub struct Telnet { /* fields omitted */ }

A telnet connection to a remote host.

Examples

use telnet::Telnet;

let mut connection = Telnet::connect(("127.0.0.1", 23), 256)
        .expect("Couldn't connect to the server...");
loop {
    let event = connection.read().expect("Read Error");
    println!("{:?}", event);
}

Methods

impl Telnet[src]

pub fn connect<A: ToSocketAddrs>(addr: A, buf_size: usize) -> Result<Telnet>[src]

Opens a telnet connection to a remote host using a TcpStream.

addr is an address of the remote host. Note that a remote host usually opens port 23 for a Telnet connection. buf_size is a size of the underlying buffer for processing the data read from the remote host.

Examples

use telnet::Telnet;

let connection = Telnet::connect(("127.0.0.1", 23), 256)
        .expect("Couldn't connect to the server...");

pub fn from_stream(stream: Box<dyn Stream>, buf_size: usize) -> Telnet[src]

Open a telnet connection to a remote host using a generic stream.

Communication will be made with the host using stream. buf_size is the size of the underlying buffer for processing data from the host.

Use this version of the constructor if you want to provide your own stream, for example if you want to mock out the remote host for testing purposes, or want to wrap the data the data with TLS encryption.

pub fn read(&mut self) -> Result<TelnetEvent>[src]

Reads a TelnetEvent.

If there was not any queued TelnetEvent, it would read a chunk of data into its buffer, extract any telnet command in the message, and queue all processed results. Otherwise, it would take a queued TelnetEvent without reading data from TcpStream.

Examples

use telnet::Telnet;

let mut connection = Telnet::connect(("127.0.0.1", 23), 256)
        .expect("Couldn't connect to the server...");
let event = connection.read().expect("Read Error");
println!("{:?}", event);

pub fn read_timeout(&mut self, timeout: Duration) -> Result<TelnetEvent>[src]

Reads a TelnetEvent, but the waiting time cannot exceed a given Duration.

This method is similar to read(), but with a time limitation. If the given time was reached, it would return TelnetEvent::TimedOut.

Examples

use std::time::Duration;
use telnet::Telnet;

let mut connection = Telnet::connect(("127.0.0.1", 23), 256)
        .expect("Couldn't connect to the server...");
let event = connection.read_timeout(Duration::new(5, 0)).expect("Read Error");
println!("{:?}", event);

pub fn read_nonblocking(&mut self) -> Result<TelnetEvent>[src]

Reads a TelnetEvent. Return immediataly if there was no queued event and nothing to read.

This method is a non-blocking version of read(). If there was no more data, it would return TelnetEvent::NoData.

Examples

use telnet::Telnet;

let mut connection = Telnet::connect(("127.0.0.1", 23), 256)
        .expect("Couldn't connect to the server...");
let event = connection.read_nonblocking().expect("Read Error");
println!("{:?}", event);

pub fn write(&mut self, data: &[u8]) -> Result<usize>[src]

Writes a given data block to the remote host. It will double any IAC byte.

Examples

use telnet::Telnet;

let mut connection = Telnet::connect(("127.0.0.1", 23), 256)
        .expect("Couldn't connect to the server...");
let buffer: [u8; 4] = [83, 76, 77, 84];
connection.write(&buffer).expect("Write Error");

pub fn negotiate(&mut self, action: NegotiationAction, opt: TelnetOption)[src]

Negotiates a telnet option with the remote host.

Examples

use telnet::{Telnet, NegotiationAction, TelnetOption};

let mut connection = Telnet::connect(("127.0.0.1", 23), 256)
        .expect("Couldn't connect to the server...");
connection.negotiate(NegotiationAction::Will, TelnetOption::Echo);

pub fn subnegotiate(&mut self, opt: TelnetOption, data: &[u8])[src]

Send data for sub-negotiation with the remote host.

Examples

use telnet::{Telnet, NegotiationAction, TelnetOption};

let mut connection = Telnet::connect(("127.0.0.1", 23), 256)
        .expect("Couldn't connect to the server...");
connection.negotiate(NegotiationAction::Do, TelnetOption::TTYPE);
let data: [u8; 1] = [1];
connection.subnegotiate(TelnetOption::TTYPE, &data);

Auto Trait Implementations

impl Unpin for Telnet

impl !Sync for Telnet

impl !Send for Telnet

impl !RefUnwindSafe for Telnet

impl !UnwindSafe for Telnet

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]