Documentation ¶
Overview ¶
Code generated by protoc-gen-go. source: MsgHead.proto DO NOT EDIT!
Index ¶
- Constants
- Variables
- func ErrCodeStrer(n32ET int32, theErrType fmt.Stringer) fmt.Stringer
- func InstallMsgMaker(handle IMessageMaker)
- func IsErrAck(msg IMsger) bool
- func MessageNamE(msgType uint16) string
- func MessageName(msg IMsger) string
- func PackMessage(msg IMsger, flag, order uint8) ([]byte, error)
- func RegistMessage(msgType uint16, msgName string, fun TMsgMakeFunc)
- func TinkerAck(req, ack IMsger)
- type EConnWay
- type IClienter
- type IMessageMaker
- type IMsger
- type ITcpConner
- type ITcpServer
- type IUdpConner
- type IUdpServer
- type IUserData
- type MsgErrAck
- type MsgHead
- func (m *MsgHead) AddFlag_(bit uint8)
- func (m *MsgHead) AddFlapP(bit uint8)
- func (m *MsgHead) AddFlapR(bit uint8)
- func (m *MsgHead) AddTrans(srcId uint32)
- func (m *MsgHead) DelFlagP(bit uint8)
- func (m *MsgHead) DelFlagR(bit uint8)
- func (m *MsgHead) DelFlag_(bit uint8)
- func (m *MsgHead) GetFlagP() uint8
- func (m *MsgHead) GetFlagR() uint8
- func (m *MsgHead) GetModule() uint16
- func (m *MsgHead) GetSubT() uint16
- func (m *MsgHead) GetType() uint16
- func (m *MsgHead) IsErrResp() bool
- func (m *MsgHead) IsRequest() bool
- func (m *MsgHead) IsRespond() bool
- func (m *MsgHead) IsTranMsg() bool
- func (m *MsgHead) IsUnknown() bool
- func (m *MsgHead) Name() string
- func (m *MsgHead) PopTrans() *Tran_
- func (m *MsgHead) ProtoMessage()
- func (m *MsgHead) Reset()
- func (m *MsgHead) SetFlagP(nFlag uint8)
- func (m *MsgHead) SetFlagR(nFlag uint8)
- func (m *MsgHead) SetModule(nModule uint16)
- func (m *MsgHead) SetSubT(sType uint16)
- func (m *MsgHead) SetTrans(trans []*Tran_)
- func (m *MsgHead) SetType(mType uint16)
- func (m *MsgHead) String() string
- type MsgUnknow
- type NetDebug
- type PackEle
- type Packet
- type PeerData
- func (this *PeerData) CalPingOverDurt() TDurt
- func (this *PeerData) ConnectId() TConnId
- func (this *PeerData) GetLastPingTime() time.Time
- func (this *PeerData) GetRemoteIP() string
- func (this *PeerData) HandInit(client IClienter) interface{}
- func (this *PeerData) SetLastPingTime(t time.Time)
- func (this *PeerData) SetRemoteIP(ip string)
- func (this *PeerData) TcpConned() bool
- func (this *PeerData) WebConned() bool
- type Response
- type TClientHandler
- type TConnHandler
- type TConnId
- type TMsgMakeFunc
- type TServerHandler
- type Tran_
- type UConnHandler
- type UMsgHandFunc
- type UServerHandler
- type WSAddr
Constants ¶
const ( DEF_PACK_HEAD_LEN = 12 // 协议头长度字节 DEF_SENDER_CSIZE = 50 // 发送队列大小 DEF_READ_DEAD_TIME = time.Minute * 2 // 读取超时时间 DEF_SEND_DEAD_TIME = time.Second * 5 // 发送超时时间 DEF_CONN_DEAD_TIME = time.Second * 5 // 连接超时时间 DEF_INFINITE_TIME = 0 // 连接无限等待 DEF_RECONNECT_TIME = time.Second * 3 // 断线重连时间 DEF_RECONNECT_MS = int(DEF_RECONNECT_TIME / time.Millisecond) DEF_UDP_LISTEN_NUM = 10 // UDP默认可监听的数量 DEF_TCPMSG_MTU_SIZE = 512 // 消息包传输最大大小 DEF_TCPMSG_MAX_SIZE = math.MaxUint16 // 消息包极限大小 65535 DEF_UDPMSG_MTU_SIZE = 1400 // 消息报传输最大大小 DEF_UDPMSG_MAX_SIZE = 1464 // 消息报极限大小 DEF_REG_MSG_MSIZE = 50 // 默认消息注册map初始大小 DEF_ACPT_CLI_MAX = 5000 // 并发连接限制 DEF_DEFAULT_MSGTYPE = 0 // 默认消息类型 DEF_CLIENT_POOL_SIZE = 50 // SocketClient Pool 大小 DEF_REISSUE_MAX_SIZE = 1000 // TcpConnect 补发列表最大值 DEF_WS_PATH_WS = "/ws" // 默认ws服务连接路径 DEF_WS_PATH_WSS = "/wss" // 默认wss服务连接路径 DEF_REQUEST_TIMEOVER = time.Second * 10 // 等待回应的请求超时时间 )
const ( PACK_FLAG_ENCRYPT = 1 << 0 // 加密 PACK_FLAG_COMPRES = 1 << 1 // 压缩 PACK_FLAG_ERRRESP = 1 << 7 // MsgErrAck PACK_FLAG_MAXIMUM = 8 // 最大值 )
const ( ECW_TCP = iota + 1 ECW_WEB ECW_MAX )
const ( MH_FIELD_MTYPE = 1 // 2 byte 主类型 MH_FIELD_STYPE = 2 // 2 byte 子类型 MH_FIELD_THEID = 3 // 4 byte 主ID MH_FIELD_MODULE = 4 // 2 byte 模块 MH_FIELD_PFLAG = 5 // 1 byte 包标记 MH_FIELD_RFLAG = 6 // 1 byte 范围标记 MH_FIELD_SESSID = 7 // 4 byte 会话ID MH_FIELD_EFFECT = 8 // 4 byte 影响ID MH_FIELD_COUNT = 9 // = 字段意义总数 MH_FIELD_FLAG_ = 10 // pass字段(服务端自用) MH_FIELD_BUFF_ = 11 // pass字段(服务端自用) )
const ( MH_FLAG_REQUEST = 1 << 0 // 请求 MH_FLAG_RESPOND = 1 << 1 // 回应 MH_FLAG_ERRRESP = 1 << 2 // 回应错误 MH_FLAG_UNKNOWN = 1 << 3 // 未知[MsgUnknow] MH_FLAG_TRANMSG = 1 << 4 // 转发 MH_FLAG_MAXIMUM = 8 // 最大数量 )
const ( M_H_FLAG_MASSMSG = 1 << 0 // 群发 M_H_FLAG_MASSSET = 1 << 1 // 群发ED M_H_FLAG_MAXIMUM = 8 // 最大数量 )
Variables ¶
var ( ErrConnTimeOut = errors.New("ErrConnectTimeOut") ErrSentTimeOut = errors.New("ErrSendRequestTimeOut") ErrMsgSocket = errors.New("ErrMsgSocketError") ErrTConnShuted = errors.New("ErrTConnShuted") ErrTConnUnable = errors.New("ErrTConnUnable") ErrSignalDone = errors.New("ErrSignalDone") ErrActivedClose = errors.New("ErrActivedClose") // 主动关闭连接 ErrPassiveClose = errors.New("ErrPassiveClose") // 被动网络原因 ErrReqTimeOver = errors.New("ErrSentRequestTimeOver") // 发送请求超时没等到回应 )
----------------------------------------------------------------------------- =================================常量定义===================================== -----------------------------------------------------------------------------
Functions ¶
func ErrCodeStrer ¶
获取正确的ErrCode字符串
func RegistMessage ¶
func RegistMessage(msgType uint16, msgName string, fun TMsgMakeFunc)
注册协议--所有协议都要先注册到系统中
Types ¶
type IClienter ¶
type IClienter interface { // 发送消息到此socket SendMsg(msg IMsger, compres ...bool) error // 发送回应到此socket SendAck(req IMsger, ack IMsger, compres ...bool) error // 发送错误回应到此socket并返回error SendErr(req IMsger, ack *MsgErrAck) error // 是否连接着的 Actived() bool // 获得此连接的唯一id ConnId() TConnId // 链接类型 ConnType() EConnWay // 对端地址IP RemoteIP() string // 对端地址IP+PORT RemoteAddr() string // 连接存活的时间 TimeLived() time.Duration // 开始连接的时间 TimeStart() time.Time // 设置绑定数据 SetUserData(data IUserData) // 获得绑定数据 GetUserData() IUserData // contains filtered or unexported methods }
SockClient接口
type IMessageMaker ¶
type IMessageMaker interface { // 打包消息 Pack(bMsg []byte, ele PackEle) ([]byte, error) // 解包消息 Unpack(bPack []byte) ([]byte, PackEle, error) // 序列化消息 Marshal(msg IMsger) ([]byte, error) // 反序列化消息 Unmarshal(bMsg []byte, ele PackEle) (IMsger, error) // 解密方法 Decrypt(src []byte) ([]byte, error) // 加密方法 Encrypt(src []byte) ([]byte, error) // 解压方法 Decompress(src []byte) ([]byte, error) // 压缩方法 Encompress(src []byte) ([]byte, error) }
系统对消息加工的接口
type IMsger ¶
type IMsger interface { // 获取消息头结构 GetHead() *MsgHead // 设置消息头结构 SetHead(head *MsgHead) // Pb的接口实现 ProtoMessage() // 格式化字符串 String() string // 重置此消息 Reset() }
----------------------------------------------------------------------------- ============================Net Message Handler============================== ----------------------------------------------------------------------------- 消息包的接口[相当于是消息的基类]
type ITcpConner ¶
type ITcpConner interface { // 继承 mss.IDebuger // 开始连接[目标主机 默认参数(DEF_INFINITE_TIME,DEF_SENDER_CSIZE)] StartConnect(desHost string) error // 开始连接[目标主机 连接超时 发送缓冲] StartConnecT(desHost string, timeout TDurt, sendCap int) error // 开始连接[全参数版] StartConnEct(desHost string, timeout TDurt, sendCap int, crypt, order, reiss bool) error // 关闭连接[ShutDown] CloseConnect() // 关闭连接[ErrReason]后还可RenewConnect ClearConnect(reason error) // 断线重新连接 RenewConnect() error // 是否连接着的 Connected() bool // 是否关闭了的 ShutDowned() bool // 目标主机信息 ConnectHost() string // 异步不等发送消息 SendMessage(msg IMsger, compres ...bool) error // 异步等待发送消息 SentRequest(req IMsger, compres ...bool) error // 同步等待发送消息 SendRequest(req IMsger, compres ...bool) (IMsger, error) // 是否开启消息加密 IsCryptMsg() bool // 是否开启消息序列 IsOrderMsg() bool // 是否开启补发 IsReissMsg() bool // 重连补发消息 ReissueMsgs() error // 设置绑定数据 SetConnData(data interface{}) // 获得绑定数据 GetConnData() interface{} }
----------------------------------------------------------------------------- ============================TCP Connect Handler============================== ----------------------------------------------------------------------------- TcpConnect 开放接口
func NewTcpConnect ¶
func NewTcpConnect(name string, handle TConnHandler) ITcpConner
创建一个TcpConnect对象
type ITcpServer ¶
type ITcpServer interface { // 继承 mss.IDebuger // 初始化参数 InitServer(maxCli, sendCap int, mustCrypt, mustOrder bool) // 开启监听[端口号] StartServe(addr string, wsAddr ...WSAddr) error // 关闭服务[主线程中调用] ShutServer() // 关闭监听 StopListen() // 监听地址 ListenTAddr() string ListenWAddr() string // 最大连接数 ClientsMax() int // 消息的chan大小 ClientCapy() int // 是否开启数据加密[同时也校验接收消息] IsMustCrypt() bool // 是否开启消息序列检测 IsMustOrder() bool // 查找client FindClient(conId TConnId) IClienter // 发送消息 SendMessage(msg IMsger, conId TConnId, compres ...bool) error // 关闭对端 CloseClient(cli IClienter, remain []Packet, reason error) }
TcpServer PUBLIC接口
func NewTcpServer ¶
func NewTcpServer(name string, handle TServerHandler) ITcpServer
创建一个TcpServer对象
type IUdpConner ¶
type IUdpConner interface { // 开始连接 StartConnect(desHost string) error // 停止连接 CloseConnect() // 目标主机 ConnectHost() string // 发送消息 SendMessage(msg IMsger) error }
UdpConnect PUBLIC接口
func NewUdpConnect ¶
func NewUdpConnect(name string, handle UConnHandler) IUdpConner
创建一个UdpConnect对象
type IUdpServer ¶
type IUdpServer interface { // 开始监听 StartListen(port int) error // 停止监听 StopListen() // 端口号 ListenPort() int // 发送消息 SendMessage(msg IMsger, addr *net.UDPAddr, packFlag ...uint8) error }
UdpServer PUBLIC接口
func NewUdpServer ¶
func NewUdpServer(name string, handle UServerHandler) IUdpServer
创建一个UdpServer对象
type IUserData ¶
type IUserData interface { // 初始化数据[返回this] HandInit(client IClienter) interface{} // 获得连接ID ConnectId() TConnId // 连接类型 TcpConned() bool WebConned() bool // 对端地址 GetRemoteIP() string SetRemoteIP(addr string) // Ping消息 CalPingOverDurt() time.Duration GetLastPingTime() time.Time SetLastPingTime(t time.Time) }
用户数据接口
type MsgErrAck ¶
type MsgErrAck struct { Head *MsgHead `protobuf:"bytes,1,opt,name=Head,json=head" json:"Head,omitempty"` T int32 `protobuf:"varint,2,opt" json:"T,omitempty"` V int64 `protobuf:"varint,3,opt" json:"V,omitempty"` E string `protobuf:"bytes,4,opt" json:"E,omitempty"` }
错误结果消息
func (*MsgErrAck) ProtoMessage ¶
func (*MsgErrAck) ProtoMessage()
type MsgHead ¶
type MsgHead struct { Types uint32 `protobuf:"varint,1,opt" json:"Types,omitempty"` TheId uint32 `protobuf:"varint,2,opt" json:"TheId,omitempty"` MFlag uint32 `protobuf:"varint,3,opt" json:"MFlag,omitempty"` SesId uint32 `protobuf:"varint,4,opt" json:"SesId,omitempty"` EffId uint32 `protobuf:"varint,5,opt" json:"EffId,omitempty"` Trans []*Tran_ `protobuf:"bytes,6,rep" json:"Trans,omitempty"` Flag_ uint32 `protobuf:"varint,7,pass" json:"-"` Buff_ []byte `protobuf:"bytes,8,pass" json:"-"` }
func (*MsgHead) ProtoMessage ¶
func (m *MsgHead) ProtoMessage()
type MsgUnknow ¶
type MsgUnknow struct { Head *MsgHead `protobuf:"bytes,1,opt,name=Head,json=head" json:"Head,omitempty"` Body []byte `protobuf:"bytes,2,pass" json:"-"` } //
无法识别的消息
func (*MsgUnknow) ProtoMessage ¶
func (m *MsgUnknow) ProtoMessage()
type NetDebug ¶
type NetDebug struct { // contains filtered or unexported fields } //
=> NetDebug inherit from mss.IDebuger
type Packet ¶
type Packet struct { // contains filtered or unexported fields } //
msg packet
func MakePacket ¶
type PeerData ¶
type PeerData struct {
// contains filtered or unexported fields
}
客户端用户数据
func (*PeerData) CalPingOverDurt ¶
func (this *PeerData) CalPingOverDurt() TDurt
func (*PeerData) GetLastPingTime ¶
func (*PeerData) GetRemoteIP ¶
func (*PeerData) SetLastPingTime ¶
func (*PeerData) SetRemoteIP ¶
type TClientHandler ¶
type TClientHandler interface { // 继承 mss.IDebuger // 所属者名称 OnTOwnerName() string // 连接发生错误 OnTClientErr(cli IClienter, remain []Packet, err error) // 处理消息 OnTClientMsg(cli IClienter, msg IMsger) // Client上的数据是否必须要加密的[true-发送时加密,接收时检测加密] OnEnMustCrypt() bool // Client上的消息是否校验order OnEnMustOrder() bool }
SocketClient 回调接口
type TConnHandler ¶
type TConnHandler interface { // 连接成功 OnTConnectOke(conndata interface{}, reconn bool) // 连接发生错误[注意主动关闭和被动关闭的多线程问题] OnTConnectErr(conndata interface{}, err error) // 处理消息 OnTConnectMsg(conndata interface{}, req, ack IMsger) // 发送请求超时 OnTConnectOut(conndata interface{}, req IMsger) }
TcpConnect 委托回调接口
type TServerHandler ¶
type TServerHandler interface { // 连接发生错误 OnTClientErr(cli IClienter, remain []Packet, err error) // 处理消息 OnTClientMsg(cli IClienter, msg IMsger) // 连接成功 OnTClientAccept(cli IClienter) }
TcpServer 委托回调接口
type Tran_ ¶
type Tran_ struct { SesId uint32 `protobuf:"varint,1,opt" json:"SesId,omitempty"` SrcId uint32 `protobuf:"varint,2,opt" json:"SrcId,omitempty"` }
func (*Tran_) ProtoMessage ¶
func (t *Tran_) ProtoMessage()
type UConnHandler ¶
type UConnHandler interface { // 处理消息 OnUConnectMsg(msg IMsger) }
UdpConnect 委托回调接口
type UMsgHandFunc ¶
----------------------------------------------------------------------------- =============================UDP Server Handler============================== ----------------------------------------------------------------------------- 消息注册函数类型
type UServerHandler ¶
UdpServer 委托回调接口