Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeMsg(m *Message) ([]byte, error)
- func EncodePkg(typ PkgType, data []byte) ([]byte, error)
- func NewAgent(conn network.Conn, connector *Connector) *agent
- func NewAgentHandler(a *agent) *agentHandler
- type Connector
- func (c *Connector) GetSessionMap() *connector.SessionMap
- func (c *Connector) OnDestroy()
- func (c *Connector) OnInit(server component.ServerImpl)
- func (c *Connector) OnRun(closeSig chan bool)
- func (c *Connector) Route(f rpc.CustomerRoute)
- func (c *Connector) SetConnectionListener(conn connector.Connection)
- func (c *Connector) SetHandlerFilter(f filter.Filter)
- type Message
- type MsgType
- type Option
- type Options
- type PkgType
Constants ¶
const ( MsgRequest MsgType = 0x00 MsgNotify = 0x01 MsgResponse = 0x02 MsgPush = 0x03 )
Message types
const ( // Handshake represents a handshake: request(client) <====> handshake response(server) PkgHandshake = 0x01 // HandshakeAck represents a handshake ack from client to server PkgHandshakeAck = 0x02 // Heartbeat represents a heartbeat PkgHeartbeat = 0x03 // Data represents a common data packet PkgData = 0x04 // Kick represents a kick off packet PkgKick = 0x05 // disconnect message from server )
const ( HeadLength = 4 MaxPacketSize = 64 * 1024 )
const ( CODE_OK = 200 CODE_USE_ERROR = 500 CODE_OLD_CLIENT = 501 )
Variables ¶
Functions ¶
func EncodeMsg ¶ added in v1.0.8
Encode marshals message to binary format. Different message types is corresponding to different message header, message types is identified by 2-4 bit of flag field. The relationship between message types and message header is presented as follows: ------------------------------------------ | type | flag | other | |----------|--------|--------------------| | request |----000-|<message id>|<route>| | notify |----001-|<route> | | response |----010-|<message id> | | push |----011-|<route> | ------------------------------------------ The figure above indicates that the bit does not affect the type of message. See ref: https://github.com/lonnng/nano/blob/master/docs/communication_protocol.md
func NewAgentHandler ¶
func NewAgentHandler(a *agent) *agentHandler
Types ¶
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
func NewConnector ¶
func (*Connector) GetSessionMap ¶
func (c *Connector) GetSessionMap() *connector.SessionMap
func (*Connector) OnInit ¶
func (c *Connector) OnInit(server component.ServerImpl)
func (*Connector) Route ¶
func (c *Connector) Route(f rpc.CustomerRoute)
func (*Connector) SetConnectionListener ¶
func (c *Connector) SetConnectionListener(conn connector.Connection)
func (*Connector) SetHandlerFilter ¶
Set a filter for client handler
type Option ¶
type Option func(*Options)
func HTTPTimeout ¶
Timeout for http handshake. Default is 10s
func HeartbeatTimeout ¶
Heartbeat timeout. Default is 10s. Disconnect if after 2*t