zNet

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: LGPL-2.1 Imports: 26 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func Dispatcher

func Dispatcher(session Session, netPacket *NetPacket) error

func GetHandler added in v0.0.2

func GetHandler() map[int32]HandlerFun

func InitDispatcherWorkerPool added in v0.0.2

func InitDispatcherWorkerPool(n int)

func InitPacket

func InitPacket(maxDataSize int32)

func InitTcpServerDefault

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

func NewHttpSession added in v0.0.2

func NewHttpSession(writer http.ResponseWriter) *httpSession

func Recover

func Recover()

func RegisterHandler

func RegisterHandler(protoId int32, fun HandlerFun) error

func SetLogPrintFunc added in v0.0.2

func SetLogPrintFunc(f LogPrintFunc)

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 HttpServer added in v0.0.2

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

func NewHttpServer added in v0.0.2

func NewHttpServer(addr string) *HttpServer

func (*HttpServer) Close added in v0.0.2

func (svr *HttpServer) Close()

func (*HttpServer) HandleFunc added in v0.0.2

func (svr *HttpServer) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*HttpServer) Start added in v0.0.2

func (svr *HttpServer) Start() error

type LogPrintFunc

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

type NetPacket

type NetPacket struct {
	ProtoId  int32
	DataSize int32
	Version  int32
	Data     []byte
}

func (*NetPacket) Marshal added in v0.0.2

func (p *NetPacket) Marshal() []byte

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 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 uint64) 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 = uint64

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()

type UdpClient added in v0.0.2

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

func (*UdpClient) Close added in v0.0.2

func (cli *UdpClient) Close()

func (*UdpClient) ConnectToServer added in v0.0.2

func (cli *UdpClient) ConnectToServer(serverAddr string, serverPort int) error

func (*UdpClient) Send added in v0.0.2

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

type UdpClientSession added in v0.0.2

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

func (*UdpClientSession) Close added in v0.0.2

func (s *UdpClientSession) Close()

func (*UdpClientSession) GetSid added in v0.0.2

func (s *UdpClientSession) GetSid() SessionIdType

func (*UdpClientSession) Init added in v0.0.2

func (s *UdpClientSession) Init(conn *net.UDPConn, aesKey []byte)

func (*UdpClientSession) Send added in v0.0.2

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

func (*UdpClientSession) Start added in v0.0.2

func (s *UdpClientSession) Start()

type UdpServer added in v0.0.2

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

func NewUdpServer added in v0.0.2

func NewUdpServer(cfg *Config) *UdpServer

func (*UdpServer) Close added in v0.0.2

func (svr *UdpServer) Close()

func (*UdpServer) GetAllSession added in v0.0.2

func (svr *UdpServer) GetAllSession() []*UdpServerSession

func (*UdpServer) GetSession added in v0.0.2

func (svr *UdpServer) GetSession(sid int64) *UdpServerSession

func (*UdpServer) RemoveSession added in v0.0.2

func (svr *UdpServer) RemoveSession(cli *UdpServerSession)

func (*UdpServer) Start added in v0.0.2

func (svr *UdpServer) Start() error

type UdpServerSession added in v0.0.2

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

func (*UdpServerSession) Close added in v0.0.2

func (s *UdpServerSession) Close()

func (*UdpServerSession) GetSid added in v0.0.2

func (s *UdpServerSession) GetSid() SessionIdType

func (*UdpServerSession) Init added in v0.0.2

func (s *UdpServerSession) Init(conn *net.UDPConn, sid SessionIdType, aesKey []byte)

func (*UdpServerSession) Receive added in v0.0.2

func (s *UdpServerSession) Receive(data []byte)

func (*UdpServerSession) Send added in v0.0.2

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

func (*UdpServerSession) Start added in v0.0.2

func (s *UdpServerSession) Start()

Jump to

Keyboard shortcuts

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