Documentation
¶
Index ¶
- Constants
- func EncodeTcpRequest(method string, params []interface{}) []byte
- type AuthConnection
- type ClientConnection
- type Connection
- type LoginAuth
- type Message
- type MsgHead
- type Response
- type TcpRequest
- type TcpSession
- func (this *TcpSession) CheckIfLogined()
- func (this *TcpSession) Close()
- func (this *TcpSession) CloseSafely()
- func (this *TcpSession) GetUserId() int64
- func (this *TcpSession) IsClosed() bool
- func (this *TcpSession) Read() *Message
- func (this *TcpSession) SetUserId(userId int64)
- func (this *TcpSession) Write(msg *Message) error
- func (this *TcpSession) WriteError(msg *Message, body string) error
Constants ¶
View Source
const ( PING uint8 = iota + 1 // 1 ENTER REQUEST RESPONSE PUSH ACK CLOSE ERR = 0xff )
View Source
const (
BYTE_PREFIX = 0xfa
)
Variables ¶
This section is empty.
Functions ¶
func EncodeTcpRequest ¶
Types ¶
type AuthConnection ¶
type AuthConnection interface {
Connection
DoAuth(session *TcpSession, auth *LoginAuth) *Response
OnAck(msg *Message)
}
type ClientConnection ¶
type ClientConnection interface {
Connection
OnAuthSuccess(session *TcpSession)
HandleResponse(msgHead MsgHead, resp map[string]interface{})
HandlePushResponse(msgHead MsgHead, method string, resp map[string]interface{})
}
type Connection ¶
type Connection interface {
OnConnected(session *TcpSession)
OnDisconnected(session *TcpSession)
HandleMessage(session *TcpSession, msg *Message)
}
type Message ¶
func NewMessage ¶
func NewMessage() *Message
type MsgHead ¶
*
- TCP包头信息
- 头格式:23字节(固定值0xfa[1字节] + 版本号[1字节] + 指令[1字节] + Flag[1字节] + 预留位[1字节] + length[2字节] + msgId[16字节])
- 版本号: 0x01 - JSON序列化
- 指令 0x01 请求消息 0x02 ACK消息
- Flag: 留给客户端标记的字节
- 预留位: 1字节
- length: Body的长度,不包括包头长度
- msgId: 消息ID[MD5值, 如 0830b69ce8af7a5e6b21658bbf5f0eeb]转换规则为每两位作为一个字节,0x08,0x30
type Response ¶
func NewResponse ¶
func NewResponse() *Response
type TcpRequest ¶
*
- method length[1字节] + method name + params length[2字节] + params
func (*TcpRequest) Decode ¶
func (this *TcpRequest) Decode(data []byte)
func (*TcpRequest) Encode ¶
func (this *TcpRequest) Encode(paramData string) []byte
type TcpSession ¶
type TcpSession struct {
Conn *net.TCPConn // socket
BR *bufio.Reader
GmtConnect time.Time
RemoteAddr string
UniqueKey string
ConnectionListener Connection
// contains filtered or unexported fields
}
TcpSession represent a user connection's context
func NewTcpSession ¶
func NewTcpSession(conn *net.TCPConn, connListener Connection) *TcpSession
func (*TcpSession) CheckIfLogined ¶
func (this *TcpSession) CheckIfLogined()
func (*TcpSession) Close ¶
func (this *TcpSession) Close()
func (*TcpSession) CloseSafely ¶
func (this *TcpSession) CloseSafely()
func (*TcpSession) GetUserId ¶
func (this *TcpSession) GetUserId() int64
func (*TcpSession) IsClosed ¶
func (this *TcpSession) IsClosed() bool
func (*TcpSession) SetUserId ¶
func (this *TcpSession) SetUserId(userId int64)
func (*TcpSession) Write ¶
func (this *TcpSession) Write(msg *Message) error
when write data error, close the connection
func (*TcpSession) WriteError ¶
func (this *TcpSession) WriteError(msg *Message, body string) error
Click to show internal directories.
Click to hide internal directories.