net

package
v0.0.0-...-98bdf84 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const HandshakeMsg = "handshake"
View Source
const HeartbeatMsg = "heartbeat"

Variables

View Source
var ConnMgr = Mgr{}

Functions

func NewServer

func NewServer(addr string, needSecret bool) *server

Types

type ClientConn

type ClientConn struct {
	Seq int64
	// contains filtered or unexported fields
}

客户端连接

func NewClientConn

func NewClientConn(wsSocket *websocket.Conn) *ClientConn

func (*ClientConn) Addr

func (this *ClientConn) Addr() string

func (*ClientConn) Close

func (this *ClientConn) Close()

func (*ClientConn) GetProperty

func (this *ClientConn) GetProperty(key string) (interface{}, error)

获取链接属性

func (*ClientConn) Push

func (this *ClientConn) Push(name string, data interface{})

func (*ClientConn) RemoveProperty

func (this *ClientConn) RemoveProperty(key string)

移除链接属性

func (*ClientConn) Send

func (this *ClientConn) Send(name string, data interface{}) *RspBody

func (*ClientConn) SetOnClose

func (this *ClientConn) SetOnClose(hookFunc func(*ClientConn))

func (*ClientConn) SetOnPush

func (this *ClientConn) SetOnPush(hookFunc func(*ClientConn, *RspBody))

func (*ClientConn) SetProperty

func (this *ClientConn) SetProperty(key string, value interface{})

设置链接属性

func (*ClientConn) Start

func (this *ClientConn) Start() bool

type Group

type Group struct {
	// contains filtered or unexported fields
}

func (*Group) AddRouter

func (this *Group) AddRouter(name string, handlerFunc HandlerFunc, middleware ...MiddlewareFunc)

func (*Group) Use

func (this *Group) Use(middleware ...MiddlewareFunc) *Group

type HandlerFunc

type HandlerFunc func(req *WsMsgReq, rsp *WsMsgRsp)

type Handshake

type Handshake struct {
	Key string `json:"key"`
}

type Heartbeat

type Heartbeat struct {
	CTime int64 `json:"ctime"`
	STime int64 `json:"stime"`
}

type Mgr

type Mgr struct {
	// contains filtered or unexported fields
}

func (*Mgr) Count

func (this *Mgr) Count() int

func (*Mgr) NewConn

func (this *Mgr) NewConn(wsSocket *websocket.Conn, needSecret bool) *ServerConn

func (*Mgr) Push

func (this *Mgr) Push(pushSync conn.PushSync)

func (*Mgr) PushByRoleId

func (this *Mgr) PushByRoleId(rid int, msgName string, data interface{}) bool

func (*Mgr) RemoveConn

func (this *Mgr) RemoveConn(conn WSConn)

func (*Mgr) RoleEnter

func (this *Mgr) RoleEnter(conn WSConn, rid int)

func (*Mgr) UserLogin

func (this *Mgr) UserLogin(conn WSConn, session string, uid int)

func (*Mgr) UserLogout

func (this *Mgr) UserLogout(conn WSConn)

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

type ProxyClient

type ProxyClient struct {
	// contains filtered or unexported fields
}

func NewProxyClient

func NewProxyClient(proxy string) *ProxyClient

func (*ProxyClient) Close

func (this *ProxyClient) Close()

func (*ProxyClient) Connect

func (this *ProxyClient) Connect() error

func (*ProxyClient) Send

func (this *ProxyClient) Send(msgName string, msg interface{}) (*RspBody, error)

func (*ProxyClient) SetOnClose

func (this *ProxyClient) SetOnClose(hookFunc func(*ClientConn))

func (*ProxyClient) SetOnPush

func (this *ProxyClient) SetOnPush(hookFunc func(*ClientConn, *RspBody))

func (*ProxyClient) SetProperty

func (this *ProxyClient) SetProperty(key string, value interface{})

type ReqBody

type ReqBody struct {
	Seq   int64       `json:"seq"`
	Name  string      `json:"name"`
	Msg   interface{} `json:"msg"`
	Proxy string      `json:"proxy"`
}

type Router

type Router struct {
	// contains filtered or unexported fields
}

func (*Router) Group

func (this *Router) Group(prefix string) *Group

func (*Router) Run

func (this *Router) Run(req *WsMsgReq, rsp *WsMsgRsp)

type RspBody

type RspBody struct {
	Seq  int64       `json:"seq"`
	Name string      `json:"name"`
	Code int         `json:"code"`
	Msg  interface{} `json:"msg"`
}

type ServerConn

type ServerConn struct {
	Seq int64
	// contains filtered or unexported fields
}

客户端连接

func NewServerConn

func NewServerConn(wsSocket *websocket.Conn, needSecret bool) *ServerConn

func (*ServerConn) Addr

func (this *ServerConn) Addr() string

func (*ServerConn) Close

func (this *ServerConn) Close()

func (*ServerConn) GetProperty

func (this *ServerConn) GetProperty(key string) (interface{}, error)

获取链接属性

func (*ServerConn) Handshake

func (this *ServerConn) Handshake()

握手协议

func (*ServerConn) Push

func (this *ServerConn) Push(name string, data interface{})

func (*ServerConn) RemoveProperty

func (this *ServerConn) RemoveProperty(key string)

移除链接属性

func (*ServerConn) Send

func (this *ServerConn) Send(name string, data interface{})

func (*ServerConn) SetOnBeforeClose

func (this *ServerConn) SetOnBeforeClose(hookFunc func(WSConn))

func (*ServerConn) SetOnClose

func (this *ServerConn) SetOnClose(hookFunc func(WSConn))

func (*ServerConn) SetProperty

func (this *ServerConn) SetProperty(key string, value interface{})

设置链接属性

func (*ServerConn) SetRouter

func (this *ServerConn) SetRouter(router *Router)

func (*ServerConn) Start

func (this *ServerConn) Start()

开启异步

type WSConn

type WSConn interface {
	SetProperty(key string, value interface{})
	GetProperty(key string) (interface{}, error)
	RemoveProperty(key string)
	Addr() string
	Push(name string, data interface{})
}

type WsMsgReq

type WsMsgReq struct {
	Body *ReqBody
	Conn WSConn
}

type WsMsgRsp

type WsMsgRsp struct {
	Body *RspBody
}

Jump to

Keyboard shortcuts

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