Documentation
¶
Index ¶
- Constants
- func Dispatcher(session Session, netPacket *NetPacket) error
- func InitPacket(maxDataSize int32)
- func InitTcpServerDefault(cfg *Config, opts ...Options)
- func Recover()
- func RegisterHandler(protoId int32, fun HandlerFun) error
- type CloseCallBackFunc
- type Config
- type HandlerFun
- type LogPrintFunc
- type NetPacket
- type Options
- func WithChanSize(chanSize int32) Options
- func WithHeartbeat(duration int) Options
- func WithLogPrintFunc(lpf LogPrintFunc) Options
- func WithMaxClientCount(maxClientCount int32) Options
- func WithMaxPacketDataSize(size int32) Options
- func WithRsaEncrypt(rsaPrivateFile string) Options
- func WithSidInitio(sidInitio int64) Options
- type Session
- type SessionCallBackFunc
- type SessionIdType
- type TcpClient
- type TcpClientSession
- type TcpServer
- func (svr *TcpServer) AddSession(conn *net.TCPConn) *TcpServerSession
- func (svr *TcpServer) Close()
- func (svr *TcpServer) GetAllSession() []*TcpServerSession
- func (svr *TcpServer) GetSession(sid int64) *TcpServerSession
- func (svr *TcpServer) RemoveSession(cli *TcpServerSession)
- func (svr *TcpServer) SetAddSessionCallBack(cb SessionCallBackFunc)
- func (svr *TcpServer) SetRemoveSessionCallBack(cb SessionCallBackFunc)
- func (svr *TcpServer) Start() error
- type TcpServerSession
Constants ¶
View Source
const DefaultPacketDataSize = int32(1024 * 1024)
View Source
const HeartbeatProtoId = int32(0)
Variables ¶
This section is empty.
Functions ¶
func Dispatcher ¶
func InitPacket ¶
func InitPacket(maxDataSize int32)
func InitTcpServerDefault ¶
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 NetPacket ¶
type NetPacket struct {
ProtoId int32 `json:"proto_id"`
DataSize int32 `json:"data_size"`
Data []byte `json:"data"`
}
func (*NetPacket) UnmarshalHead ¶
type Options ¶
type Options func(*TcpServer)
func WithChanSize ¶
func WithHeartbeat ¶
func WithLogPrintFunc ¶
func WithLogPrintFunc(lpf LogPrintFunc) Options
func WithMaxClientCount ¶
func WithMaxPacketDataSize ¶
func WithRsaEncrypt ¶
func WithSidInitio ¶
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) ConnectToServer ¶
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) 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 (*TcpServer) AddSession ¶
func (svr *TcpServer) AddSession(conn *net.TCPConn) *TcpServerSession
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)
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) Start ¶
func (s *TcpServerSession) Start()
Click to show internal directories.
Click to hide internal directories.