udp

package
v0.0.0-...-5a37ffa Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const Guar_NO = uint8(0x55) //01010101
View Source
const Guar_YES = uint8(0xAA) //10101010
View Source
const MSG_HEADER_LEN = 8 //unsafe.Sizeof(p)

************ 消息头的相关处理 ************

   0    1    2    3    4    5    6    7
-----------------------------------------
|Guar|Ver | MsgLen  | MsgType |  MsgId  |
-----------------------------------------
|      Body...                          |
-----------------------------------------

Variables

This section is empty.

Functions

func Register

func Register(msg IMsg) (err error)

Register msg要先注册后,才能正确接收该类型的数据

func Start

func Start(ctx context.Context, wg *sync.WaitGroup, logT *log.TraceInfoST, conf *conf.Config) (
	recvCh, sendCh channel.IChanN, err error)

Start udp接口启动的时候执行,inCh, outCh是输入、输出chan,为了和后端处理模块解耦

func String

func String() string

Types

type Conn

type Conn struct {
	*sync.Mutex //kcp操作锁,因为有可能并发创建kcp,所以必须在Conn创建之初创建锁
	// contains filtered or unexported fields
}

Conn 每条连接建立一个Conn

type Header struct {
	Guar uint8  // 是否保证到达,即是否通过KCP发送,guarantee缩写;01010101不可靠传输,10101010可靠传输
	Ver  uint8  // 版本号
	Len  uint16 // 消息体的长度
	Type uint16 // 消息类型
	ID   uint16 // 消息ID
}

func (*Header) Deserialize

func (p *Header) Deserialize(data []byte) ([]byte, error)

func (*Header) Serialize

func (p *Header) Serialize(data []byte) ([]byte, error)

Serialize 在传入的切片上序列化本对象,返回未使用的切片

type IMsg

type IMsg interface {
	RecvMsg(pSess *session.Session, log *log.TraceInfoST) (msgs []PkgRtn, err error)
	IMsgRtn
}

IMsg 是路由层(消息分发层)和逻辑层(消息处理层)之间传递的数据结构,Msg:message的缩写

type IMsgRtn

type IMsgRtn interface {
	MsgNO() uint16 //消息编号

	//以下是 proto.Message 接口的所有方法,所以IWsRequest是可以转化为 proto.Message 接口的
	Reset()
	String() string
	ProtoMessage()
}

IMsgRtn 是路由层(消息分发层)和逻辑层(消息处理层)之间传递的数据结构,Msg:message的缩写

type Pkg

type Pkg struct {
	//MsgType uint16
	Guar   bool   //是否保证到达,false表示不保证到达
	ConnID uint64 //UserID uint64 // 用于获取UDPAddr;
	Msg    IMsg

	LogT *log.TraceInfoST
}

Pkg 是用于在IO层(消息收发层)和路由层(消息分发层)之间交互的消息

type PkgRtn

type PkgRtn struct {
	//MsgType uint16
	Guar   bool   //是否保证到达,false表示不保证到达
	ConnID uint64 //用于获取UDPAddr; 有可能要给其他用户发消息,比如单用户多设备登陆踢人的时候,还要跨服踢人!放cache服务器里设个标志,“惰性踢人”!
	Msg    IMsgRtn

	LogT *log.TraceInfoST
}

MsgRtn 是RecvMsg()方法的返回值,Msg:message的缩写,Rtn:return的缩写

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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