Documentation ¶
Index ¶
- Constants
- Variables
- func ParseJSONConfig(config *KcpConfig, path string) error
- type KcpConfig
- type KcpConn
- func (c *KcpConn) Close()
- func (c *KcpConn) CloseSocket()
- func (c *KcpConn) GetNetConn() net.Conn
- func (c *KcpConn) GetUserData() interface{}
- func (c *KcpConn) InitData()
- func (c *KcpConn) RemoteAddr() string
- func (c *KcpConn) RemoveData()
- func (c *KcpConn) Send(data []byte) int
- func (c *KcpConn) SendDirect(data []byte) int
- func (c *KcpConn) SendPak(val interface{}) int
- func (c *KcpConn) SendPakDirect(val interface{}) int
- func (c *KcpConn) SetUserData(user interface{})
- type KcpNetwork
Constants ¶
View Source
const ( RMStream = iota // 使用流算法读写数据包 RMReadFull // 使用固定算法读写数据包 固定算法 包头4字节为固定长度,其余位置为数据包payload )
Variables ¶
View Source
var (
HandlerProc = 1
)
Functions ¶
func ParseJSONConfig ¶
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
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 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) CloseSocket ¶
func (c *KcpConn) CloseSocket()
func (*KcpConn) GetNetConn ¶
func (*KcpConn) GetUserData ¶
func (c *KcpConn) GetUserData() interface{}
func (*KcpConn) RemoteAddr ¶
func (*KcpConn) RemoveData ¶
func (c *KcpConn) RemoveData()
func (*KcpConn) SendDirect ¶
func (*KcpConn) SendPakDirect ¶
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()
Click to show internal directories.
Click to hide internal directories.