kcpNet

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: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RMStream   = iota // 使用流算法读写数据包
	RMReadFull        // 使用固定算法读写数据包 固定算法 包头4字节为固定长度,其余位置为数据包payload
)

Variables

View Source
var (
	HandlerProc = 1
)

Functions

func ParseJSONConfig

func ParseJSONConfig(config *KcpConfig, path string) error

Types

type KcpConfig

type KcpConfig struct {
	AutoExpire   int    `json:"autoexpire"`
	ScavengeTTL  int    `json:"scavengettl"`
	Crypt        string `json:"crypt"`
	CryptKey     string `json:"key"`
	Mode         string `json:"mode"`
	MTU          int    `json:"mtu"`
	SndWnd       int    `json:"sndwnd"`
	RcvWnd       int    `json:"rcvwnd"`
	DataShard    int    `json:"datashard"`
	ParityShard  int    `json:"parityshard"`
	DSCP         int    `json:"dscp"`
	NoComp       bool   `json:"nocomp"`
	AckNodelay   bool   `json:"acknodelay"`
	NoDelay      int    `json:"nodelay"`
	Interval     int    `json:"interval"`
	Resend       int    `json:"resend"`
	NoCongestion int    `json:"nc"`
	SockBuf      int    `json:"sockbuf"`
	KeepAlive    int    `json:"keepalive"`
	Readtimeout  int    `json:"readTimeout"`
	Writetimeout int    `json:"writeTimeout"`
	Log          bool   `json:"log"`
	SnmpLog      string `json:"snmplog"`
	SnmpPeriod   int    `json:"snmpperiod"`
	Pprof        bool   `json:"pprof"`
	Quiet        bool   `json:"quiet"`
	Recvmode     int    `json:"recevMode"`
}

Config for server

func NewConfig

func NewConfig() *KcpConfig

type KcpConn

type KcpConn struct {
	cm.Conn

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

	CryptKey []byte

	IsClosed int32
	// contains filtered or unexported fields
}

func EmptyConn

func EmptyConn(ctype int) *KcpConn

func NewConn

func NewConn(tn *KcpNetwork, conn *kcp.UDPSession, UData interface{}) *KcpConn

func NewDial

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

func (*KcpConn) Close

func (c *KcpConn) Close()

func (*KcpConn) CloseSocket

func (c *KcpConn) CloseSocket()

func (*KcpConn) GetNetConn

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

func (*KcpConn) GetUserData

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

func (*KcpConn) InitData

func (c *KcpConn) InitData()

func (*KcpConn) RemoteAddr

func (c *KcpConn) RemoteAddr() string

func (*KcpConn) RemoveData

func (c *KcpConn) RemoveData()

func (*KcpConn) Send

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

func (*KcpConn) SendDirect

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

func (*KcpConn) SendPak

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

func (*KcpConn) SendPakDirect

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

func (*KcpConn) SetUserData

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

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

type KcpNetwork

type KcpNetwork struct {
	NetCM *cm.ConnManager

	KcpConf *KcpConfig

	RecvMode int

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

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

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

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

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

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

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

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

func NewEmptyKcp

func NewEmptyKcp(cnf *KcpConfig) *KcpNetwork

func NewKcpServer

func NewKcpServer(addr string, cnf *KcpConfig) (tcp *KcpNetwork, err error)

func (*KcpNetwork) Dial

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

func (*KcpNetwork) RemoveSession

func (c *KcpNetwork) RemoveSession(sessionId string)

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

func (*KcpNetwork) Runnable

func (c *KcpNetwork) Runnable()

Jump to

Keyboard shortcuts

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