sxchange

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CB

type CB func([]byte, *Connection)

CB type for callback function for each type of transfered data

type Connection

type Connection struct {
	AESKey string // AES-128/192/256 key in hex for connecton encryption

	Types          map[uint8]DataTypeCB // map of type->params&callback
	KeepAlive      time.Duration        // tcp keep-alive
	ReadTimeout    time.Duration        // we need to receive new message at least once per this duration
	WriteTimeout   time.Duration        // maximal duration for every write operation
	ConnectTimeout time.Duration        // maximum duration of net.Dial
	MaxSize        uint32               // maximum number of bytes for one record/message
	Ctx            context.Context      // context for some values like server id
	CloseChan      chan interface{}     // channel for closing incoming messages circle
	// contains filtered or unexported fields
}

Connection informaion both for client or server

func (*Connection) Connect

func (c *Connection) Connect(address string) error

Connect to remote server

func (*Connection) ListenOne

func (c *Connection) ListenOne(address string, onConnect func(*Connection, <-chan interface{}), onError func(err error)) error

ListenOne is one-connection server

func (*Connection) Remote

func (c *Connection) Remote() net.Addr

Remote address retrive

func (*Connection) WriteMsg

func (c *Connection) WriteMsg(msgType uint8, msg []byte) error

WriteMsg creates header and then writes msg buffer via TCP connection

type DataTypeCB

type DataTypeCB struct {
	SizeBytes int8  // -1 for fixed size, 0 for no data (ping?), 1 for 0-255 bytes, 2 for 0-65535 bytes...
	FixedSize int32 // if some struct has fixed fize no other header needed
	Callback  CB    // which function to run after data received
}

DataTypeCB describes

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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