Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandleFunc ¶
HandleFunc 处理连接业务的函数 *net.TCPConn:与客户端的连接 []byte 处理的数据 int 处理数据的长度
type IConnManager ¶
type IConnManager interface {
// AddConn 添加新的连接
AddConn(connection IConnection)
// RemoveConn 删除连接
RemoveConn(connection IConnection)
// GetConn 获取连接
GetConn(connID uint32) (IConnection, error)
// GetConnCnt 获取连接个数
GetConnCnt() int
// RemoveAllConn 删除所有连接
RemoveAllConn()
}
IConnManager 连接管理器
type IConnection ¶
type IConnection interface {
// Start 启动连接
Start()
// Stop 停止连接
Stop()
// GetTCPConnection 获取当前连接绑定的 socket conn
GetTCPConnection() *net.TCPConn
// GetConnID 获取当前连接模块的连接 ID
GetConnID() int32
// RemoteAddr 获取远程客户端的 TCP 状态,IP 和 Port
RemoteAddr() net.Addr
// SendMsg 将数据进行封包,然后发送给远程客户端
SendMsg(msgID uint32, data []byte) error
}
type IMessage ¶
type IMessage interface {
GetMsgID() uint32 // 获取消息 ID
GetMsgLen() uint32 // 获取消息长度
GetMsgData() []byte // 获取消息内容
SetMsgID(uint32) // 设置消息 ID
SetMsgData([]byte) // 设置消息内容
SetMsgLen(uint32) // 设置消息长度
}
IMessage 消息接口
type IMsgHandler ¶
type IRequest ¶
type IRequest interface {
// GetConn 得到当前连接
GetConn() IConnection
// GetData 得到请求的消息数据
GetData() []byte
GetMsgID() uint32
GetMsgLen() uint32
}
IRequest 接口。用于将客户端的请求的连接信息和数据信息封装到一起
type IServer ¶
type IServer interface {
// Start 启动服务器
Start()
// Stop 停止服务器
Stop()
// Serve 运行服务器
Serve()
// AddRouter 给 server 添加 Router
AddRouter(msgID uint32, router Router)
// GetConnManager 获取连接管理器
GetConnManager() IConnManager
// SetOnConnStart 设置 conn start hook
SetOnConnStart(f func(connection IConnection))
// SetOnConnClose 设置 conn close hook
SetOnConnClose(f func(connection IConnection))
// CallOnConnStart 调用 hook
CallOnConnStart(conn IConnection)
// CallOnConnClose 调用 hook
CallOnConnClose(conn IConnection)
}
IServer 服务器通用接口
Click to show internal directories.
Click to hide internal directories.