Documentation
¶
Overview ¶
Package cbufftcpserver tcp server
Index ¶
- type Config
- type CtcpsvrSt
- func (t *CtcpsvrSt) CloseClient(clientID uint64, reason string)
- func (t *CtcpsvrSt) CloseClients(clientIDs []uint64, reason string)
- func (t *CtcpsvrSt) SendToAllClients(msg interface{}) error
- func (t *CtcpsvrSt) SendToClient(clientID uint64, msg interface{}) error
- func (t *CtcpsvrSt) StartServer(iPort uint16) error
- func (t *CtcpsvrSt) StopServer() error
- type EventHandler
- type ProtocolIF
- type ServerStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// AsyncReceive after recieve a whole package, the receive callback will go sync or async
AsyncReceive bool
}
Config extra config
type CtcpsvrSt ¶
type CtcpsvrSt struct {
// contains filtered or unexported fields
}
CtcpsvrSt tcp server instance
func NewTCPSvr ¶
func NewTCPSvr(eventCb EventHandler, cnf Config) *CtcpsvrSt
NewTCPSvr new ctcpserver object
func (*CtcpsvrSt) CloseClient ¶
CloseClient close one client
func (*CtcpsvrSt) CloseClients ¶
CloseClients close clients
func (*CtcpsvrSt) SendToAllClients ¶
SendToAllClients send to all clients
func (*CtcpsvrSt) SendToClient ¶
SendToClient sent to client
func (*CtcpsvrSt) StartServer ¶
StartServer start server
type EventHandler ¶
type EventHandler interface {
// new connections event
OnNewConnection(clientID uint64, clientIP string, clientAddr string)
// disconnected event
OnDisconnected(clientID uint64, clientIP string, clientAddr string)
// receive data event
OnReceiveData(clientID uint64, clientIP string, clientAddr string, pPacks []interface{})
// data already sended event
OnSendedData(clientID uint64, clientIP string, clientAddr string, msg interface{}, bysSended []byte, length int)
// error
OnError(msg string, err error)
// error
OnCliError(clientID uint64, clientIP string, clientAddr string, msg string, err error)
// error
OnCliErrorStr(clientID uint64, clientIP string, clientAddr string, msg string)
// data protocol
ProtocolIF
}
EventHandler server callback control handler
type ProtocolIF ¶
type ProtocolIF interface {
// pack message into the []byte to be written
Pack(clientID uint64, cliIP string, cliAddr string, msg interface{}) ([]byte, error)
// depack the message packages from read []byte
Depack(clientID uint64, cliIP string, cliAddr string, rawData []byte) ([]byte, []interface{})
}
ProtocolIF interface to self define pack and depack
type ServerStatus ¶
type ServerStatus int
ServerStatus server status
const ( // ServerStatusClosed closed ServerStatusClosed ServerStatus = 0 // ServerStatusStarting starting ServerStatusStarting ServerStatus = 1 // ServerStatusRunning running ServerStatusRunning ServerStatus = 2 // ServerStatusStopping stopping ServerStatusStopping ServerStatus = 3 )
Click to show internal directories.
Click to hide internal directories.