echo

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: MIT Imports: 9 Imported by: 0

README

Echo

v0.1.2

Go Reference

What

TCP Echo server. RFC862 implementation.

Usage of package

package main

import (
	"context"

	"github.com/boratanrikulu/echo"
)

func main() {
	s := echo.NewServer().
		Address(":1337").
		Banner(true).
		Verbose(false)

	ctx := context.Background()
	s.Run(ctx)
}

Usage of CLI

               _
              | |
  ___    ___  | |__     ___
 / _ \  / __| | '_ \   / _ \
|  __/ | (__  | | | | | (_) |
 \___|  \___| |_| |_|  \___/

Usage: echo [options]
Options:
	-a,  --address,   which interface and port will be used  *[example: ":1337"]
	-n,  --no-banner
	-v,  --verbose
	-h,  --help

* means "must be set".

Live Demo

It lives at echo.bora.sh:1337.
You can try it using telnet.

telnet echo.bora.sh 1337

Development

To run tests,

go test ./... -v -cover -count=1 -race

To run server,

go run ./cmd --address :1337

To run server with Docker,

docker build -t echo .
docker run --rm -i -t -p 1337:1337 echo --address :1337

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrListenerFail = errors.New("starting listener is failed")
	ErrNoAddress    = errors.New("server address is not defined")
)

Functions

func Listen

func Listen(network, address string) (net.Listener, error)

Listen returns a listener that supports SO_REUSEADDR and SO_REUSEPORT.

Types

type EchoTCP

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

EchoTCP keeps net.Listener and verbose status.

func NewEchoTCP

func NewEchoTCP(address string, verbose bool) (*EchoTCP, error)

NewEchoTCP returns a new EchoTCP.

func (*EchoTCP) Run

func (et *EchoTCP) Run(ctx context.Context)

Run starts accepting connections.

type Server

type Server interface {
	Address(string) Server
	Banner(bool) Server
	Verbose(bool) Server
	Run(context.Context)
}

Server gives you higher abstraction for Echo Server.

func NewServer

func NewServer() Server

NewServer returns a new server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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