grapeWSNet

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

Overview

Websocket Network version 1.0 beta by koangel email: jackliu100@gmail.com 2017/8/3

Index

Constants

View Source
const (
	ReadWaitPing = 120 * time.Second
	WriteTicker  = 2 * time.Minute
)
View Source
const (
	BinaryMsg = websocket.BinaryMessage
	TextMsg   = websocket.TextMessage
)

Variables

View Source
var (
	HandlerProc = 1
)

Functions

This section is empty.

Types

type WSConn

type WSConn struct {
	cm.Conn

	WConn    *ws.Conn
	UserData interface{} // 用户对象
	LastPing time.Time

	CryptKey []byte

	IsClosed int32

	RMData sync.Once
	// contains filtered or unexported fields
}

func NewDial

func NewDial(wn *WSNetwork, addr, sOrigin string, UData interface{}) (conn *WSConn, err error)

func NewWConn

func NewWConn(wn *WSNetwork, Conn *ws.Conn, UData interface{}) *WSConn

///////////////////////////////////////////// 新建WS

func (*WSConn) Close

func (c *WSConn) Close()

func (*WSConn) CloseSocket

func (c *WSConn) CloseSocket()

func (*WSConn) GetConn

func (c *WSConn) GetConn() *ws.Conn

func (*WSConn) GetNetConn

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

func (*WSConn) GetUserData

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

func (*WSConn) InitData

func (c *WSConn) InitData()

func (*WSConn) RemoteAddr

func (c *WSConn) RemoteAddr() string

func (*WSConn) RemoveData

func (c *WSConn) RemoveData()

func (*WSConn) Send

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

func (*WSConn) SendDirect

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

func (*WSConn) SendPak

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

func (*WSConn) SendPakDirect

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

func (*WSConn) SetReadTimeout

func (c *WSConn) SetReadTimeout(t time.Duration)

func (*WSConn) SetUserData

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

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

func (*WSConn) SetWriteTimeout

func (c *WSConn) SetWriteTimeout(t time.Duration)

type WSNetwork

type WSNetwork struct {
	Origin string

	ChkOrigin bool

	NetCM *cm.ConnManager

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

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

	// 连接安全性检测 server only
	OnUpgrade func(req *http.Request) bool

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

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

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

	HttpHome func(w http.ResponseWriter, r *http.Request)

	MsgType int
	// contains filtered or unexported fields
}

func NetEmptyWS

func NetEmptyWS(Origin, wPath string) *WSNetwork

//////////////////////////////////// 新建函数

func NewWebsocket

func NewWebsocket(addr, Origin, wPath string) *WSNetwork

func (*WSNetwork) Dial

func (c *WSNetwork) Dial(addr string) (conn *WSConn, err error)

func (*WSNetwork) RemoveSession

func (c *WSNetwork) RemoveSession(sessionId string)

func (*WSNetwork) Runnable

func (c *WSNetwork) Runnable()

func (*WSNetwork) SetBinaryMessage

func (c *WSNetwork) SetBinaryMessage()

func (*WSNetwork) SetTextMessage

func (c *WSNetwork) SetTextMessage()

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

Jump to

Keyboard shortcuts

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