qtcp

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Bytes = &myBytes{}
View Source
var (
	ErrConnClosed = errors.New("the connection has been closed")
)

Functions

func CRC16

func CRC16(pucFrame []byte, usLen int) int

func Check

func Check(e error)

Check 检测并抛出异常

func CheckSum

func CheckSum(data []byte) uint16

func Recover

func Recover() error

Recover 收集异常

Types

type CheckPacketCallBack

type CheckPacketCallBack func(pack Packet) ([]byte, bool)

type Client

type Client interface {
	Connection
	Stop()
}

func NewClient

func NewClient(svrAddr string, buffLength int, protocol PackProtocol, callback ConnCallback, relinkWaitTime, keepAlivePeriod time.Duration) Client

type ConnCallback

type ConnCallback interface {
	OnLinked(c Connection)
	OnReceived(c Connection, packet Packet)
	OnClosed(c Connection)
	OnErrored(e error, c Connection)
}

ConnCallback 建立连接时的委托定义

type Connection

type Connection interface {
	Start()
	Send(pack Packet, timeout time.Duration) error
	GetId() int64
	IsClosed() bool
}

type ECheckType

type ECheckType byte
const (
	ECheckTypeNone     ECheckType = 0
	ECheckTypeCheckSum ECheckType = 1
	ECheckTypeCRC16    ECheckType = 4
)

func (ECheckType) ToString

func (v ECheckType) ToString() (string, error)

type PackProtocol

type PackProtocol interface {
	//GetFrame 组包 如果成功 推一个包到接收缓冲区
	GetFrame(b *[]byte, recChan chan<- Packet) error
	BuildFrame(typeBytes, content []byte) (Packet, error)
}

PackProtocol 封包协议

func NewFHProtocol

func NewFHProtocol(head []byte, typeLen, lenSize int, bigEndian bool, checkType ECheckType) PackProtocol

NewFHProtocol 新建固定包头协议 head 特征头 typeLen 包类型长度 字节 lenSize 包长位数 仅支持8 16 32 CheckType 校验方法

func NewHatProtocol

func NewHatProtocol(head, tail []byte, typeLen int, checkType ECheckType) PackProtocol

type Packet

type Packet interface {
	// Marshal 编码方法 数据包必需实现将其内容格式化为byte数组的编码方法
	Marshal() []byte

	Split() (frameType, body []byte)
}

Packet 数据包

type Server

type Server interface {
	Start()
	Stop()
}

func NewServer

func NewServer(port int, acceptTimeout, keepAlivePeriod time.Duration, buffLength int, callback ConnCallback, protocol PackProtocol) Server

Jump to

Keyboard shortcuts

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