Documentation ¶
Index ¶
- Constants
- func Dispatcher(session Session, netPacket *NetPacket) error
- func GetHandler() map[int32]HandlerFun
- func InitDispatcherWorkerPool(n int)
- func InitPacket(maxDataSize int32)
- func InitTcpServerDefault(cfg *Config, opts ...Options)
- func NewHttpSession(writer http.ResponseWriter) *httpSession
- func Recover()
- func RegisterHandler(protoId int32, fun HandlerFun) error
- func SetLogPrintFunc(f LogPrintFunc)
- type CloseCallBackFunc
- type Config
- type HandlerFun
- type HttpServer
- type LogPrintFunc
- type NetPacket
- type 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
- type UdpClient
- type UdpClientSession
- type UdpServer
- type UdpServerSession
- func (s *UdpServerSession) Close()
- func (s *UdpServerSession) GetSid() SessionIdType
- func (s *UdpServerSession) Init(conn *net.UDPConn, sid SessionIdType, aesKey []byte)
- func (s *UdpServerSession) Receive(data []byte)
- func (s *UdpServerSession) Send(protoId int32, data []byte) error
- func (s *UdpServerSession) Start()
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 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 NewHttpSession ¶ added in v0.0.2
func NewHttpSession(writer http.ResponseWriter) *httpSession
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 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 NetPacket ¶
func (*NetPacket) UnmarshalHead ¶
type Options ¶
type Options func(*TcpServer)
func WithChanSize ¶
func WithHeartbeat ¶
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 = uint64
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()
type UdpClient ¶ added in v0.0.2
type UdpClient struct {
// contains filtered or unexported fields
}
func (*UdpClient) ConnectToServer ¶ added in v0.0.2
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 (*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)
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()
Click to show internal directories.
Click to hide internal directories.