telnet

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package telnet is SSHYard's Telnet client (RFC 854/855) over any byte stream. It negotiates options with the RFC 1143 Q method, answers TERMINAL-TYPE and NAWS, measures round trips with TIMING-MARK, and hands the caller the server's data with the protocol stripped, ready for a terminal emulator.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("telnet: connection closed")

ErrClosed reports a probe cut short by the end of the connection.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a Telnet client session over rw. Read is meant for one goroutine; Write, Resize, Probe and Close may be called from others.

func New

func New(rw io.ReadWriteCloser, o Options) *Conn

New starts a Telnet session on rw and sends the client's opening offers (WILL NAWS, WILL TTYPE, DO ECHO, WILL SGA, DO SGA). A failure to send them shows up on the next Read or Write.

func (*Conn) Break

func (c *Conn) Break(d time.Duration) error

Break sends BRK, Telnet's break: the line is not held, so d is not used.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the transport, ending any probe in flight.

func (*Conn) Probe

func (c *Conn) Probe(ctx context.Context) (time.Duration, error)

Probe measures a round trip with TIMING-MARK (RFC 860): it sends DO TIMING-MARK and waits for the server's WILL or WONT, which the goroutine calling Read picks up, so Read must be running. Probes run one at a time; a concurrent Probe waits its turn. It returns ctx.Err() when ctx ends first and ErrClosed when the connection does.

func (*Conn) Read

func (c *Conn) Read(p []byte) (int, error)

Read returns the server's data, protocol stripped. It returns io.EOF itself when the server closes the connection; other errors are returned as the transport gave them.

func (*Conn) Resize

func (c *Conn) Resize(cols, rows int) error

Resize remembers the window size and sends it if NAWS is on. Sizes are clamped to 1..65535.

func (*Conn) Write

func (c *Conn) Write(p []byte) (int, error)

Write sends user data, doubling IAC and, unless we send binary, turning a CR not followed by LF into CR NUL. It returns len(p) on success.

type Options

type Options struct {
	Term       string // answered to TERMINAL-TYPE (RFC 1091); "" is "xterm-256color"
	Cols, Rows int    // initial window size for NAWS (RFC 1073)
}

Options configure a Conn.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL