conn

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrForciblyClosed   = errors.New("connection was forcibly closed")
	ErrClosed           = errors.New("closed")
	ErrConnectionClosed = errors.New("connection closed")
	ErrBadPackage       = errors.New("bad package data")
	ErrReadTimeout      = errors.New("i/o timeout")
)

Functions

This section is empty.

Types

type Connection

type Connection interface {
	// Write message to the connection.
	Write(data []byte) error
	// Read message from the connection.
	Read() ([]byte, error)
	// Close the connection.
	Close() error
	// GetConnInfo return the connection info
	GetConnInfo() *ConnectionInfo
}

Connection expression a network keep-alive connection, WebSocket, tcp etc

type ConnectionHandler

type ConnectionHandler func(conn Connection)

type ConnectionInfo

type ConnectionInfo struct {
	Ip   string
	Port int
	Addr string
}

type ConnectionProxy

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

ConnectionProxy expression a binder of Connection.

func (ConnectionProxy) Close

func (c ConnectionProxy) Close() error

func (ConnectionProxy) GetConnInfo

func (c ConnectionProxy) GetConnInfo() *ConnectionInfo

func (ConnectionProxy) Read

func (c ConnectionProxy) Read() ([]byte, error)

func (ConnectionProxy) Write

func (c ConnectionProxy) Write(data []byte) error

type Server

type Server interface {
	SetConnHandler(handler ConnectionHandler)
	Run(host string, port int) error
}

func NewWsServer

func NewWsServer(options *WsServerOptions) Server

NewWsServer options can be nil, use default value when nil.

type TcpConnection

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

func NewTcpConn

func NewTcpConn(c *net.TCPConn) *TcpConnection

func (TcpConnection) Close

func (t TcpConnection) Close() error

func (TcpConnection) GetConnInfo

func (t TcpConnection) GetConnInfo() *ConnectionInfo

func (TcpConnection) Read

func (t TcpConnection) Read() ([]byte, error)

func (TcpConnection) Write

func (t TcpConnection) Write(data []byte) error

type TcpServer

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

func NewTcpServer

func NewTcpServer() *TcpServer

func (*TcpServer) Run

func (t *TcpServer) Run(host string, port int) error

func (*TcpServer) SetConnHandler

func (t *TcpServer) SetConnHandler(handler ConnectionHandler)

type WsConnection

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

func NewWsConnection

func NewWsConnection(conn *websocket.Conn, options *WsServerOptions) *WsConnection

func (*WsConnection) Close

func (c *WsConnection) Close() error

func (*WsConnection) GetConnInfo

func (c *WsConnection) GetConnInfo() *ConnectionInfo

func (*WsConnection) Read

func (c *WsConnection) Read() ([]byte, error)

func (*WsConnection) Write

func (c *WsConnection) Write(data []byte) error

type WsServer

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

func (*WsServer) Run

func (ws *WsServer) Run(host string, port int) error

func (*WsServer) SetConnHandler

func (ws *WsServer) SetConnHandler(handler ConnectionHandler)

type WsServerOptions

type WsServerOptions struct {
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

Jump to

Keyboard shortcuts

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