net

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMLI

func AddMLI(mliType MliType, data []byte) []byte

AddMLI adds a MLI to the payload

func HandleError

func HandleError(err error)

Types

type EchoServ

type EchoServ struct {
	TcpAddr *net.TCPAddr
}

func (*EchoServ) ListenAndAccept

func (echoServer *EchoServ) ListenAndAccept() (err error)

type MliType

type MliType string
const (
	Mli2i MliType = "2i"
	Mli2e MliType = "2e"
	Mli4e MliType = "4e"
	Mli4i MliType = "4i"
)

type NetCatClient

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

NetCatClient is network TCP client that can be used to send/receive length-delimited messages like 2E,2I, 4E, 4I etc

func NewNetCatClient

func NewNetCatClient(addr string, mliType MliType) *NetCatClient

NewNetCatClient returns a new netcat client associated with the given mli-type and connecting to the addr

func (*NetCatClient) Close

func (nt *NetCatClient) Close()

Close closes the client side of the connection

func (*NetCatClient) IsConnected

func (nt *NetCatClient) IsConnected() bool

func (*NetCatClient) OpenConnection

func (nt *NetCatClient) OpenConnection() (err error)

OpenConnection opens a connection to the server

func (*NetCatClient) Read

func (nt *NetCatClient) Read(opts *ReadOptions) ([]byte, error)

func (*NetCatClient) ReadDirect added in v1.0.0

func (nt *NetCatClient) ReadDirect(data []byte) (n int, err error)

ReadDirect reads requested data from the socket directly. Use this with caution because the caller is responsible for reading length prefix and knowing when one packet starts and ends

func (*NetCatClient) ReadNextPacket deprecated

func (nt *NetCatClient) ReadNextPacket() ([]byte, error)

ReadNextPacket reads the next data segment (as per MLI type associated with nt)

Deprecated:: Please use Read(*ReadOptions)

func (*NetCatClient) Write

func (nt *NetCatClient) Write(data []byte) (err error)

Write writes data into the socket after adding the necessary length prefix as per the MLI type set on the netcat client

type ReadOptions added in v1.0.0

type ReadOptions struct {
	Deadline time.Time
}

ReadOptions are set of options that can be associated with a connection

type TcpHost

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

func NewTcpHost

func NewTcpHost(mliType MliType, tcpAddr *net.TCPAddr) *TcpHost

func (*TcpHost) SetHandler

func (tcpHost *TcpHost) SetHandler(handler TcpMessageHandler)

func (*TcpHost) Start

func (tcpHost *TcpHost) Start()

type TcpMessageHandler

type TcpMessageHandler interface {
	HandleMessage(clientCon *net.TCPConn, msgData []byte)
}

Jump to

Keyboard shortcuts

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