comet

package module
v0.0.0-...-6f867e4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: MIT Imports: 14 Imported by: 1

README

comet

comet

Documentation

Index

Constants

View Source
const (
	//# 对称加密key
	CryptoKey = "Adba723b7fe06819"
)

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(rawData string, key []byte) (string, error)

func Encrypt

func Encrypt(rawData, key []byte) (string, error)

func GenCid

func GenCid() string

对称加密IP和端口,当做clientId

func GetAddrByCid

func GetAddrByCid(cId string) (addr string)

获取client key地址信息

func NewComet

func NewComet() *comet

初始化comet

Types

type Conn

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

func (*Conn) AsyncWrite

func (c *Conn) AsyncWrite(buf []byte) error

AsyncWrite writes data to client/connection asynchronously, usually you would call it in individual goroutines instead of the event-loop goroutines.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the current connection.

func (*Conn) Context

func (c *Conn) Context() (ctx interface{})

Context returns a user-defined context.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() (addr net.Addr)

LocalAddr is the connection's local socket address.

func (*Conn) Read

func (c *Conn) Read() (buf []byte)

Read reads all data from inbound ring-buffer and event-loop-buffer without moving "read" pointer, which means it does not evict the data from buffers actually and those data will present in buffers until the ResetBuffer method is called.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() (addr net.Addr)

RemoteAddr is the connection's remote peer address.

func (*Conn) SetContext

func (c *Conn) SetContext(ctx interface{})

SetContext sets a user-defined context.

type ConnectHandler

type ConnectHandler struct {
	sync.Map
}

连接管理

func ConnectHandlerIns

func ConnectHandlerIns() *ConnectHandler

连接管理单例

func (*ConnectHandler) C

func (c *ConnectHandler) C(k, v interface{})

func (*ConnectHandler) Clear

func (c *ConnectHandler) Clear()

清空

func (*ConnectHandler) D

func (c *ConnectHandler) D(k interface{})

func (*ConnectHandler) Each

func (c *ConnectHandler) Each(fu func(k, v interface{}) bool)

遍历

func (*ConnectHandler) R

func (c *ConnectHandler) R(k interface{}) (interface{}, bool)

func (*ConnectHandler) Size

func (c *ConnectHandler) Size() int64

大小

func (*ConnectHandler) U

func (c *ConnectHandler) U(k, v interface{}) (interface{}, bool)

type IConn

type IConn interface {

	// Context returns a user-defined context.
	Context() (ctx interface{})

	// SetContext sets a user-defined context.
	SetContext(ctx interface{})

	// LocalAddr is the connection's local socket address.
	LocalAddr() (addr net.Addr)

	// RemoteAddr is the connection's remote peer address.
	RemoteAddr() (addr net.Addr)

	// Read reads all data from inbound ring-buffer and event-loop-buffer without moving "read" pointer, which means
	// it does not evict the data from buffers actually and those data will present in buffers until the
	// ResetBuffer method is called.
	Read() (buf []byte)

	// AsyncWrite writes data to client/connection asynchronously, usually you would call it in individual goroutines
	// instead of the event-loop goroutines.
	AsyncWrite(buf []byte) error

	// Close closes the current connection.
	Close() error
}

func NewConn

func NewConn(uid string, conn gnet.Conn) IConn

type IEvent

type IEvent interface {
	// Parameter:out is the return value which is going to be sent back to the client.
	OnMessage(frame []byte, c IConn)
	// OnClosed fires when a connection has been closed.
	// The parameter:err is the last known connection error.
	OnClosed(c IConn, err error)
}

type IServer

type IServer interface {
	// 启动zim服务
	Serve(event IEvent, port int)
	// 停止zim服务
	Stop()
}

func NewServer

func NewServer() IServer

初始化zim服务

type TCPHandler

type TCPHandler struct {
	*gnet.EventServer
	// contains filtered or unexported fields
}

tcp event

func TCPHandlerIns

func TCPHandlerIns(event IEvent) *TCPHandler

Tcp 服务单例

func (*TCPHandler) GetConn

func (eh *TCPHandler) GetConn(c gnet.Conn) IConn

* 返回连接

func (*TCPHandler) OnClosed

func (eh *TCPHandler) OnClosed(c gnet.Conn, err error) (action gnet.Action)

gnet 连接断开

func (*TCPHandler) OnInitComplete

func (eh *TCPHandler) OnInitComplete(server gnet.Server) (action gnet.Action)

gnet 服务启动成功

func (*TCPHandler) OnOpened

func (eh *TCPHandler) OnOpened(c gnet.Conn) (out []byte, action gnet.Action)

gnet 新建连接

func (*TCPHandler) React

func (eh *TCPHandler) React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action)

接收数据

func (*TCPHandler) Release

func (eh *TCPHandler) Release()

回收资源

func (*TCPHandler) Size

func (eh *TCPHandler) Size() int64

Size 在线人数

type WSSHandler

type WSSHandler struct {
	*gnet.EventServer
	// contains filtered or unexported fields
}

wss event

func WSSHandlerIns

func WSSHandlerIns() *WSSHandler

wss 服务单例

func (*WSSHandler) Release

func (ws *WSSHandler) Release()

回收资源

Jump to

Keyboard shortcuts

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