mgate

package
v0.0.0-...-ce26905 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright 2014 loolgame Author. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 与客户端通信的自定义粘包示例,需要mqant v1.6.4版本以上才能运行 该示例只用于简单的演示,并没有实现具体的粘包协议

* 一定要记得在confin.json配置这个模块的参数,否则无法使用

Index

Constants

This section is empty.

Variables

View Source
var Module = func() module.Module {
	gate := new(Gate)
	return gate
}

Functions

This section is empty.

Types

type CustomAgent

type CustomAgent struct {
	gate.Agent
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent(module module.RPCModule) *CustomAgent

func (*CustomAgent) Close

func (this *CustomAgent) Close()

func (*CustomAgent) Destroy

func (this *CustomAgent) Destroy()

func (*CustomAgent) GetSession

func (this *CustomAgent) GetSession() gate.Session

func (*CustomAgent) IsClosed

func (this *CustomAgent) IsClosed() bool

func (*CustomAgent) OnClose

func (this *CustomAgent) OnClose() error

func (*CustomAgent) OnInit

func (this *CustomAgent) OnInit(gate gate.Gate, conn network.Conn) error

func (*CustomAgent) OnRecover

func (this *CustomAgent) OnRecover(topic string, msg []byte)

* 接收到一个数据包

func (*CustomAgent) RevNum

func (this *CustomAgent) RevNum() int64

func (*CustomAgent) Run

func (this *CustomAgent) Run() (err error)

func (*CustomAgent) SendNum

func (this *CustomAgent) SendNum() int64

func (*CustomAgent) WriteMsg

func (this *CustomAgent) WriteMsg(topic string, body []byte) error

* 给客户端发送消息

type Gate

type Gate struct {
	basegate.Gate //继承
}

func (*Gate) Connect

func (this *Gate) Connect(session gate.Session)

当连接建立 并且MQTT协议握手成功

func (*Gate) Delete

func (gate *Gate) Delete(session gate.Session) (err error)

* 强制删除Session信息

func (*Gate) DisConnect

func (this *Gate) DisConnect(session gate.Session)

当连接关闭 或者客户端主动发送MQTT DisConnect命令 ,这个函数中Session无法再继续后续的设置操作,只能读取部分配置内容了

func (*Gate) GetType

func (this *Gate) GetType() string

func (*Gate) Heartbeat

func (gate *Gate) Heartbeat(session gate.Session)

* 用户心跳,一般用户在线时60s发送一次 可以用来延长Session信息过期时间

func (*Gate) OnInit

func (this *Gate) OnInit(app module.App, settings *conf.ModuleSettings)

func (*Gate) OnRequestTracing

func (gate *Gate) OnRequestTracing(session gate.Session, topic string, msg []byte) bool

* 是否需要对本次客户端请求进行跟踪

func (*Gate) Query

func (gate *Gate) Query(Userid string) ([]byte, error)

* 获取用户Session信息 用户登录以后会调用Query获取最新信息

func (*Gate) Storage

func (gate *Gate) Storage(session gate.Session) (err error)

* 存储用户的Session信息 Session Bind Userid以后每次设置 settings都会调用一次Storage

func (*Gate) Version

func (this *Gate) Version() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL