ListenManager

package
v0.0.0-...-155bb80 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

TcpManager project TcpManager.go

ListenManager document

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSever

func CreateSever(ip_address string, logicChannel chan proto.Message)

ip_address是带端口的字符串 比如 127.0.0.1:8008, logicChannel是将网络层消息传递给逻辑层主线程的管道

func DecodePackage

func DecodePackage(pkg *bytes.Buffer, recvData []byte) []byte

接收消息要处理粘包的解包函数 pkg是ConnectionSession的cache,如果根据头4个字节获取的报文长度大于当前pkg的len-4的长度,那么说明还有后续消息没有read,还需要继续等待。这时返回nil []byte 反之如果长度小于等于当前pkg的len-4的长度说明,说明已经获取了一个完整的消息,就把头四个字节去掉,然后把实际报文return出去

func EncodePackage

func EncodePackage(pkg *bytes.Buffer, data []byte) error

发消息时调用的组包函数

Types

type ConnectionSession

type ConnectionSession struct {
	MsgWriteCh chan *bs_tcp.TCPTransferMsg //从接受来自逻辑层消息的管道

	IsSendKickMsg int32 //MsgPool是否处理了Kick报文或者说是否已经调用了CloseSession的标志位,MsgPool也会访问,所以大写
	// contains filtered or unexported fields
}

服务端的

func GetSessionByConnId

func GetSessionByConnId(connId uint64) *ConnectionSession

func (*ConnectionSession) CloseSession

func (session *ConnectionSession) CloseSession(logicChannel chan proto.Message)

CloseSession必须由逻辑层创建协程来调用,因为这里使用了session.wg.Wait()阻塞,而且必须先判断之前是否已经调用了CloseSession,不能调用两次

func (*ConnectionSession) RecvPackege

func (session *ConnectionSession) RecvPackege(logicChannel chan proto.Message)

应对粘包采用的数据格式是4个字节的int32类型的length变量作为包头,后续跟上长度为length的包实体 从客户端收消息

func (*ConnectionSession) SendPackege

func (session *ConnectionSession) SendPackege(logicChannel chan proto.Message)

向客户端发消息

Jump to

Keyboard shortcuts

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