session

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: MIT Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFoundSession    = errors.New("the session not found in the group")
	ErrInvalidSessionKind = errors.New("invalid session kind")
)

Functions

This section is empty.

Types

type Group

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

func NewGroup

func NewGroup() *Group

func (*Group) AddSession

func (g *Group) AddSession(sess *Session)

AddSession 添加会话

func (*Group) Broadcast

func (g *Group) Broadcast(kind Kind, msg []byte, msgType ...int) (n int, err error)

Broadcast 推送广播消息(异步)

func (*Group) GetSession

func (g *Group) GetSession(kind Kind, target int64) (*Session, error)

GetSession 获取会话

func (*Group) Multicast

func (g *Group) Multicast(kind Kind, targets []int64, msg []byte, msgType ...int) (n int, err error)

Multicast 推送组播消息(异步)

func (*Group) Push

func (g *Group) Push(kind Kind, target int64, msg []byte, msgType ...int) error

Push 推送消息(异步)

func (*Group) RemSession

func (g *Group) RemSession(kind Kind, target int64) (*Session, error)

RemSession 移除会话

func (*Group) Send

func (g *Group) Send(kind Kind, target int64, msg []byte, typ ...int) error

Send 发送消息(同步)

type Kind

type Kind int
const (
	Conn Kind = iota + 1 // 连接SESSION
	User                 // 用户SESSION
)

type Session

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

func NewSession

func NewSession() *Session

func (*Session) AddToGroups added in v0.0.4

func (s *Session) AddToGroups(groups ...*Group)

AddToGroups 添加到会话组

func (*Session) Bind

func (s *Session) Bind(uid int64)

Bind 绑定用户ID

func (*Session) CID

func (s *Session) CID() int64

CID 获取连接ID

func (*Session) Close added in v0.0.3

func (s *Session) Close(isForce ...bool) error

Close 关闭会话

func (*Session) Init

func (s *Session) Init(conn network.Conn)

Init 初始化会话

func (*Session) LocalAddr

func (s *Session) LocalAddr() (net.Addr, error)

LocalAddr 获取本地地址

func (*Session) LocalIP

func (s *Session) LocalIP() (string, error)

LocalIP 获取本地IP

func (*Session) Push

func (s *Session) Push(msg []byte, msgType ...int) error

Push 发送消息(异步)

func (*Session) RemFromGroups added in v0.0.4

func (s *Session) RemFromGroups(groups ...*Group)

RemFromGroups 从会话组移除

func (*Session) RemoteAddr

func (s *Session) RemoteAddr() (net.Addr, error)

RemoteAddr 获取远端地址

func (*Session) RemoteIP

func (s *Session) RemoteIP() (string, error)

RemoteIP 获取远端IP

func (*Session) Reset

func (s *Session) Reset()

Reset 重置会话

func (*Session) Send

func (s *Session) Send(msg []byte, msgType ...int) error

Send 发送消息(同步)

func (*Session) UID

func (s *Session) UID() int64

UID 获取用户ID

func (*Session) Unbind added in v0.0.4

func (s *Session) Unbind(uid int64)

Unbind 解绑用户ID

Jump to

Keyboard shortcuts

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