Git Product home page Git Product logo

telnet's Introduction

Package telnet

The telnet package provides basic telnet client and server implementations for Go, including handling of IACs and extensible telnet option negotiation.

Currently both the basic client and server are implemented, as well as a NAWS client/server handler as a working example. Additional handlers may be added to the core library over time (feel free to submit a PR if you've written one you'd like to see added!)

Usage

Running a server:

svr := telnet.NewServer(":9999", telnet.HandleFunc(func(c *telnet.Connection){
	log.Printf("Connection received: %s", c.RemoteAddr())
	c.Write([]byte("Hello world!\r\n"))
	c.Close()
}))
svr.ListenAndServe()

The server API is modeled after the net/http API, so it should be easy to get your bearings; of course, telnet and HTTP are very different beasts, so the similarities are somewhat limited. The server listens on a TCP address for new connections. Whenever a new connection is received, the connection handler is called with the connection object. This object is a wrapper for the underlying TCP connection, which aims to transparently handle IAC. There is a slightly more complex example located in the example package.

Running a client is pretty simple:

conn, err := telnet.Dial("127.0.0.1:9999")

This is really straightforward - dial out, get a telnet connection handler back. Again, this handles IAC transparently, and like the Server, can take a list of optional IAC handlers. Bear in mind that some handlers - for example, the included NAWS handler - use different Option functions to register them with a client versus a server; this is because they may behave differently at each end. See the documentation for the options for more details.

Linereader

A sub-package, linereader, exposes a simple reader intended to be run in a Goroutine, which consumes lines from an io.Reader and sends them over a channel for asynchronous handling.

Thanks

This package was forked from github.com/aprice/telnet. Thanks to aprice for the initial implementation.

telnet's People

Contributors

matjam avatar aprice avatar

Stargazers

Damian Peckett avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.