grapeNet

package
v0.0.0-...-5771147 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReadWaitPing = 65 * time.Second
	WriteTicker  = 45 * time.Second
)
View Source
const (
	RMStream     = iota // 使用流算法读写数据包
	RMReadFull          // 使用固定算法读写数据包 固定算法 包头4字节为固定长度,其余位置为数据包payload
	RMStringLine        // 通过使用\n来进行文本拆分
)

Variables

View Source
var (
	HandlerProc = 1
)

Functions

This section is empty.

Types

type TCPNetwork

type TCPNetwork struct {
	NetCM *cm.ConnManager

	RecvMode  int
	SendRetry int

	UseHeaderLen bool // 是否自动附加头部4字节(RMFULL模式下强制附加)

	/// 所有的callBack函数
	// 创建用户DATA
	CreateUserData func() interface{}

	// 通知连接
	OnAccept func(conn *TcpConn)
	// 数据包进入
	OnHandler func(conn *TcpConn, ownerPak []byte)
	// 连接关闭
	OnClose func(conn *TcpConn)
	// 连接成功
	OnConnected func(conn *TcpConn)

	MainProc func() // 简易主处理函数

	// 打包以及加密行为
	Package   func(val interface{}) (data []byte, err error)
	Unpackage func(conn *TcpConn, spak *stream.BufferIO) (data [][]byte, err error)

	// 输出panic数据
	Panic func(conn *TcpConn, src string)

	Encrypt func(data, key []byte) []byte
	Decrypt func(data, key []byte) []byte

	// ping,pong CALL
	SendPing func(conn *TcpConn)
	SendPong func(conn *TcpConn, ping []byte) bool
	// contains filtered or unexported fields
}

func NewEmptyTcp

func NewEmptyTcp(mode int) *TCPNetwork

func NewTcpServer

func NewTcpServer(mode int, addr string) (tcp *TCPNetwork, err error)

/////////////////////////// 创建网络服务器

func (*TCPNetwork) Dial

func (c *TCPNetwork) Dial(addr string, UserData interface{}) (conn *TcpConn, err error)

func (*TCPNetwork) RemoveSession

func (c *TCPNetwork) RemoveSession(sessionId string)

////////////////////////// 成员函数

func (*TCPNetwork) Runnable

func (c *TCPNetwork) Runnable()

type TcpConn

type TcpConn struct {
	cm.Conn

	TConn    net.Conn    // tcp连接
	UserData interface{} // 用户对象
	LastPing time.Time

	CryptKey []byte

	IsClosed int32

	ReadTime  time.Duration
	WriteTime time.Duration
	// contains filtered or unexported fields
}

func EmptyConn

func EmptyConn(ctype int) *TcpConn

func NewConn

func NewConn(tn *TCPNetwork, conn net.Conn, UData interface{}) *TcpConn

func NewDial

func NewDial(tn *TCPNetwork, addr string, UData interface{}) (conn *TcpConn, err error)

func (*TcpConn) Close

func (c *TcpConn) Close()

func (*TcpConn) CloseSocket

func (c *TcpConn) CloseSocket()

func (*TcpConn) GetNetConn

func (c *TcpConn) GetNetConn() net.Conn

func (*TcpConn) GetUserData

func (c *TcpConn) GetUserData() interface{}

func (*TcpConn) InitData

func (c *TcpConn) InitData()

func (*TcpConn) RemoteAddr

func (c *TcpConn) RemoteAddr() string

func (*TcpConn) RemoveData

func (c *TcpConn) RemoveData()

func (*TcpConn) Send

func (c *TcpConn) Send(data []byte) int

func (*TcpConn) SendDirect

func (c *TcpConn) SendDirect(data []byte) int

func (*TcpConn) SendPak

func (c *TcpConn) SendPak(val interface{}) int

func (*TcpConn) SendPakDirect

func (c *TcpConn) SendPakDirect(val interface{}) int

func (*TcpConn) SetReadTime

func (c *TcpConn) SetReadTime(d time.Duration)

//////////////////////////////////////////// 成员函数

func (*TcpConn) SetUserData

func (c *TcpConn) SetUserData(user interface{})

func (*TcpConn) SetWriteTime

func (c *TcpConn) SetWriteTime(w time.Duration)

Jump to

Keyboard shortcuts

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