zNet

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: LGPL-2.1 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPacketDataSize = int32(1024 * 1024)
View Source
const HeartbeatProtoId = int32(0)

Variables

This section is empty.

Functions

func Dispatcher

func Dispatcher(session Session, netPacket *NetPacket) error

func InitPacket

func InitPacket(maxDataSize int32)

func InitTcpServerDefault

func InitTcpServerDefault(cfg *Config, opts ...Options)

func Recover

func Recover()

func RegisterHandler

func RegisterHandler(protoId int32, fun HandlerFun) error

Types

type CloseCallBackFunc

type CloseCallBackFunc func(c *TcpServerSession)

type Config

type Config struct {
	MaxPacketDataSize int32  `toml:"max_packet_data_size" json:"max_packet_data_size"` //default 1024*1024
	ListenAddress     string `toml:"listen_address" json:"listen_address"`             //default ":9016"
	MaxClientCount    int32  `toml:"max_client_count" json:"max_client_count"`         //default 10000
	ChanSize          int32  `toml:"chan_size" json:"chan_size"`                       //session receive and send chanel size, default 2048
	HeartbeatDuration int    `toml:"heartbeat_duration" json:"heartbeat_duration"`     //default 30s
}
var GConfig *Config

type HandlerFun

type HandlerFun func(session Session, protoId int32, data []byte)

type LogPrintFunc

type LogPrintFunc func(v ...any)
var LogPrint LogPrintFunc = log.Println

type NetPacket

type NetPacket struct {
	ProtoId  int32  `json:"proto_id"`
	DataSize int32  `json:"data_size"`
	Data     []byte `json:"data"`
}

func (*NetPacket) UnmarshalHead

func (p *NetPacket) UnmarshalHead(data []byte) error

type Options

type Options func(*TcpServer)

func WithChanSize

func WithChanSize(chanSize int32) Options

func WithHeartbeat

func WithHeartbeat(duration int) Options

func WithLogPrintFunc

func WithLogPrintFunc(lpf LogPrintFunc) Options

func WithMaxClientCount

func WithMaxClientCount(maxClientCount int32) Options

func WithMaxPacketDataSize

func WithMaxPacketDataSize(size int32) Options

func WithRsaEncrypt

func WithRsaEncrypt(rsaPrivateFile string) Options

func WithSidInitio

func WithSidInitio(sidInitio int64) Options

type Session

type Session interface {
	Send(protoId int32, data []byte) error
	GetSid() SessionIdType
}

type SessionCallBackFunc

type SessionCallBackFunc func(sid SessionIdType)

type SessionIdType

type SessionIdType int64

type TcpClient

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

func (*TcpClient) Close

func (cli *TcpClient) Close()

func (*TcpClient) ConnectToServer

func (cli *TcpClient) ConnectToServer(serverAddr string, serverPort int, rsaPublicFile string, heartbeatDuration int) error

func (*TcpClient) Send

func (cli *TcpClient) Send(protoId int32, data []byte) error

type TcpClientSession

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

func (*TcpClientSession) Close

func (s *TcpClientSession) Close()

func (*TcpClientSession) GetSid

func (s *TcpClientSession) GetSid() SessionIdType

func (*TcpClientSession) Init

func (s *TcpClientSession) Init(conn *net.TCPConn, aesKey []byte, heartbeatDuration int)

func (*TcpClientSession) Send

func (s *TcpClientSession) Send(protoId int32, data []byte) error

func (*TcpClientSession) Start

func (s *TcpClientSession) Start()

type TcpServer

type TcpServer struct {
	// contains filtered or unexported fields
}
var TcpServerInstance *TcpServer

func GetTcpServerDefault

func GetTcpServerDefault() *TcpServer

func NewTcpServer

func NewTcpServer(cfg *Config, opts ...Options) *TcpServer

func (*TcpServer) AddSession

func (svr *TcpServer) AddSession(conn *net.TCPConn) *TcpServerSession

func (*TcpServer) Close

func (svr *TcpServer) Close()

func (*TcpServer) GetAllSession

func (svr *TcpServer) GetAllSession() []*TcpServerSession

func (*TcpServer) GetSession

func (svr *TcpServer) GetSession(sid int64) *TcpServerSession

func (*TcpServer) RemoveSession

func (svr *TcpServer) RemoveSession(cli *TcpServerSession)

func (*TcpServer) SetAddSessionCallBack

func (svr *TcpServer) SetAddSessionCallBack(cb SessionCallBackFunc)

func (*TcpServer) SetRemoveSessionCallBack

func (svr *TcpServer) SetRemoveSessionCallBack(cb SessionCallBackFunc)

func (*TcpServer) Start

func (svr *TcpServer) Start() error

type TcpServerSession

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

func (*TcpServerSession) Close

func (s *TcpServerSession) Close()

func (*TcpServerSession) GetSid

func (s *TcpServerSession) GetSid() SessionIdType

func (*TcpServerSession) Init

func (s *TcpServerSession) Init(conn *net.TCPConn, sid SessionIdType, closeCallBack CloseCallBackFunc, aesKey []byte)

func (*TcpServerSession) Send

func (s *TcpServerSession) Send(protoId int32, data []byte) error

func (*TcpServerSession) Start

func (s *TcpServerSession) Start()

Jump to

Keyboard shortcuts

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