netutil

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//消息报头字节数
	HEAD_SIZE = 4
	//消息号占用的字节数
	MSG_ID_SIZE = 2
)
View Source
const (
	SESS_KEYEXCG = 0x1 // 是否已经交换完毕KEY
	SESS_ENCRYPT = 0x2 // 是否可以开始加密
)
View Source
const (
	PACKET_LIMIT = 65536
)

Variables

View Source
var (
	ServerEndian = binary.LittleEndian
)

Functions

This section is empty.

Types

type NetConnIF

type NetConnIF interface {
	SetReadDeadline(t time.Time) error
	Close() error
	SetWriteDeadline(t time.Time) error
	Write(b []byte) (n int, err error)
	RemoteAddr() net.Addr
	Read(p []byte) (n int, err error)
}

type NetPacket

type NetPacket struct {
	MsgId   uint16
	Data    []byte
	Session *TCPSession
}

type TCPSession

type TCPSession struct {
	//*net.TCPConn
	Conn     NetConnIF
	SendChan chan *NetPacket
	ReadChan chan *NetPacket
	//离线消息管道,用于外部接收连接断开的消息并处理后续
	OffChan chan int64
	// ID
	SessionId int64
	// 会话标记
	Flag int32

	// Declares how many times we will try to resend message
	MaxSendRetries int

	CloseState chanutil.DoneChan

	OnLineTime  int64
	OffLineTime int64

	EncodeKey []byte
	DecodeKey []byte
	// contains filtered or unexported fields
}

func NewSession

func NewSession(conn NetConnIF, readChan, sendChan chan *NetPacket, offChan chan int64) *TCPSession

func (*TCPSession) Close

func (s *TCPSession) Close()

func (*TCPSession) DirectSend

func (s *TCPSession) DirectSend(packet *NetPacket) bool

func (*TCPSession) DirectSendAndClose added in v1.1.2

func (s *TCPSession) DirectSendAndClose(packet *NetPacket)

func (*TCPSession) HandleConn

func (s *TCPSession) HandleConn(filter func(*NetPacket) bool)

func (*TCPSession) IsClosed added in v1.0.7

func (s *TCPSession) IsClosed() bool

func (*TCPSession) ParsePacket

func (s *TCPSession) ParsePacket(pkt []byte) *NetPacket

func (*TCPSession) ReadLoop

func (s *TCPSession) ReadLoop(filter func(*NetPacket) bool)

func (*TCPSession) RemoteAddr added in v1.0.7

func (s *TCPSession) RemoteAddr() net.Addr

网络连接远程ip

func (*TCPSession) RemoteIp added in v1.0.7

func (s *TCPSession) RemoteIp() string

网络连接远程ip

func (*TCPSession) Send

func (s *TCPSession) Send(packet *NetPacket) bool

func (*TCPSession) SendLoop added in v1.0.7

func (s *TCPSession) SendLoop()

func (*TCPSession) SetCipher

func (s *TCPSession) SetCipher(encodeKey, decodeKey []byte) error

RC4加密解密

func (*TCPSession) SetParameter

func (s *TCPSession) SetParameter(readDelay, sendDelay time.Duration, maxRecvSize uint32, sendFullClose bool)

设置链接参数

func (*TCPSession) SetRpmParameter

func (s *TCPSession) SetRpmParameter(rpmLimit uint32, rpmInterval int64, msg *NetPacket)

包频率控制参数

func (*TCPSession) TraceErrorf added in v1.0.10

func (s *TCPSession) TraceErrorf(format string, a ...interface{})

func (*TCPSession) TraceFinish added in v1.0.10

func (s *TCPSession) TraceFinish(traceDefer func(*expvar.Map, int64))

func (*TCPSession) TracePrintf added in v1.0.10

func (s *TCPSession) TracePrintf(format string, a ...interface{})

func (*TCPSession) TraceStart added in v1.0.10

func (s *TCPSession) TraceStart(family, title string, expvar bool)

Jump to

Keyboard shortcuts

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