Documentation
¶
Overview ¶
Package gote (go-telnet) provides a net.Conn compatible interface for connection to telnet servers that require telnet option negotiation. Behavior mimics net.Conn behavior wherever possible, exceptions noted.
Index ¶
Examples ¶
Constants ¶
View Source
const ( IAC = byte(255) DONT = byte(254) DO = byte(253) WONT = byte(252) WILL = byte(251) SB = byte(250) // Sub Negotiation GA = byte(249) // Go Ahead EL = byte(248) // Erase Line EC = byte(247) // Erase Character AYT = byte(246) // Are You There AO = byte(245) // Abort Operation IP = byte(244) // Interrupt Process BRK = byte(243) // Break NOP = byte(241) // No operation SE = byte(240) // End of Subnegotiation )
Commands
View Source
const ( BIN = byte(0) // Binary Transmission ECHO = byte(1) REC = byte(2) // Reconnect SGA = byte(3) // Suppress Go Ahead LOG = byte(18) // Logout TSP = byte(32) // Terminal Speed RFC = byte(33) // Remote Flow Control )
Options
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection interface {
// Read the data sent from the server after being processed
// for telnet options.
Read(b []byte) (n int, err error)
// Write the byte buffer to the output stream. Escaping 255 bytes is done
// automatically, so is not required by the caller. Note that the written
// count may be off due to the 255 byte escaping.
Write(b []byte) (n int, err error)
// Close the connection
// This is a pass-through method to the underlying net.conn
// without any processing.
Close() error
// LocalAddr returns the LocalAddress of this connection.
// This is a pass-through method to the underlying net.conn
// without any processing.
LocalAddr() net.Addr
// RemoteAddr returns the RemoteAddress of this connection.
// This is a pass-through method to the underlying net.conn
// without any processing.
RemoteAddr() net.Addr
// SetDeadline is a pass-through method to the underlying net.conn
// without any processing.
SetDeadline(t time.Time) error
// SetReadDeadline is a pass-through method to the underlying net.conn
// without any processing.
SetReadDeadline(t time.Time) error
// SetWriteDeadline is a pass-through method to the underlying net.conn
// without any processing.
SetWriteDeadline(t time.Time) error
}
Connection is a telnet interface which implements net.conn, along with some proposed extended functionality for handling telnet options.
func Dial ¶
func Dial(network, address string) (Connection, error)
Dial connects to a TCP endpoint and returns a Telnet Connection object, which transparently handles telnet options and escaping.
Example ¶
// Dial the telnet server
conn, err := gote.Dial("tcp", "rainmaker.wunderground.com")
if err != nil {
panic("Unable to connect.")
}
// Read 30 bytes from the stream
buf := make([]byte, 30)
_, err = conn.Read(buf)
if err != nil {
panic("Unable to read from stream.")
}
// Write 'Hello World' to the stream.
_, err = conn.Write([]byte("Hello world!"))
func DialTimeout ¶
func DialTimeout(network, address string, timeout time.Duration) (Connection, error)
Click to show internal directories.
Click to hide internal directories.