tran

package
v0.0.0-...-e38a99a Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LF the string of linefeed
	LF = "\n"
)

Variables

View Source
var (
	// EndIdentity the network communication end identity
	EndIdentity = []byte("_$#END#$_")
	// ErrorIdentity the network communication error identity
	ErrorIdentity = []byte("_$#ERR#$_")
	// ErrorEndIdentity the network communication end identity with error identity
	ErrorEndIdentity = append(ErrorIdentity, EndIdentity...)
	// LFBytes the linefeed bytes
	LFBytes = []byte(LF)
)
View Source
var (
	// ServerExecuteError the remote server execute error
	ServerExecuteError = errors.New("server execute error")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	// Connect connect to the server
	Connect() error
	// Write write data to the server
	Write(data []byte) error
	// ReadAll read all the data of the server
	ReadAll() (data []byte, err error)
	// Host return the client host
	Host() string
	// Port return the client bind port
	Port() int
	// Close close the client connection
	Close() error
	// IsClosed is connection closed of the current client
	IsClosed() bool
}

Client a network communication client

func NewClient

func NewClient(host string, port int, enableTLS bool) Client

NewClient create an instance of tcpClient

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewConn

func NewConn(conn net.Conn) *Conn

NewConn create a Conn instance

func (*Conn) Authorized

func (conn *Conn) Authorized() bool

func (*Conn) CheckPerm

func (conn *Conn) CheckPerm(perm auth.Perm) bool

func (*Conn) MarkAuthorized

func (conn *Conn) MarkAuthorized(user *auth.HashUser)

func (*Conn) StartAuthCheck

func (conn *Conn) StartAuthCheck()

StartAuthCheck auto check auth state per second, close the connection if unauthorized after one minute

func (*Conn) StopAuthCheck

func (conn *Conn) StopAuthCheck()

StopAuthCheck stop auto auth check

type Server

type Server interface {
	// Listen listen the specified port to wait client connect
	Listen() error
	// Accept accept the client connection
	Accept(process func(client *Conn, data []byte)) error
	// ClientCount the client count of the connected
	ClientCount() int
	// Send send the data to the client
	Send([]byte) error
	// Host return the server host
	Host() string
	// Port return the server bind port
	Port() int
	// Close close the server
	Close() error
	// Auth client sign in
	Auth(user *auth.HashUser) (bool, auth.Perm)
}

Server a network communication server

func NewServer

func NewServer(ip string, port int, enableTLS bool, certFile string, keyFile string, users []*auth.User) Server

NewServer create an instance of tcpServer

Jump to

Keyboard shortcuts

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