Help us shape the future of Go! Take the 2026 Go Developer Survey

tcpconnect

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package tcpconnect provides a tcp dialer with a two-channel []byte{} interface (In, Out)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EchoHandler

func EchoHandler(ctx context.Context, c *TCPconnect)

EchoHandler is for testing (it echoes messages)

func SpeakThenEchoHandler

func SpeakThenEchoHandler(ctx context.Context, c *TCPconnect)

SpeakThenEchoHandler is used for testing (it says something then echoes)

Types

type TCPconnect

type TCPconnect struct {
	// In channel carries messages FROM TCP conn
	In chan []byte

	//Out channel carries messages TO TCP conn
	Out chan []byte

	// MaxFrameBytes represents the maximum size of a single message
	MaxFrameBytes int

	// Listeners is a list of connections when in listening mode
	Listeners []*TCPconnect

	// ID identifies the instance, useful for logging
	ID string

	// Conn holds a pointer to the net.conn
	Conn *net.Conn
}

TCPconnect represents a TCP connection

func New

func New() *TCPconnect

New returns a pointer to new TCPconnect struct

func (*TCPconnect) Dial

func (c *TCPconnect) Dial(ctx context.Context, uri string)

Dial starts a connection to the given URI

func (*TCPconnect) Echo

func (c *TCPconnect) Echo(ctx context.Context, uri string)

Echo echoes messages (used for testing)

func (*TCPconnect) HandleConn

func (c *TCPconnect) HandleConn(ctx context.Context, conn net.Conn)

HandleConn handles connections, including reading and writing

func (*TCPconnect) Listen

func (c *TCPconnect) Listen(ctx context.Context, uri string, handler func(context.Context, *TCPconnect))

Listen returns new conns over a channel for use by other handlers

func (*TCPconnect) WithConn

func (c *TCPconnect) WithConn(conn *net.Conn) *TCPconnect

WithConn sets which net.Conn is used

func (*TCPconnect) WithMaxFrameBytes

func (c *TCPconnect) WithMaxFrameBytes(max int) *TCPconnect

WithMaxFrameBytes sets the maximum bytes that can be sent per frame this impacts memory usage (larger max frame sizes require more memory for the buffer)

Jump to

Keyboard shortcuts

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