connector

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CODE_OK         = 200
	CODE_USE_ERROR  = 500
	CODE_OLD_CLIENT = 501
)

Variables

This section is empty.

Functions

func NewAgent

func NewAgent(conn network.Conn, connector *Connector) *agent

func NewAgentHandler

func NewAgentHandler(a *agent) *agentHandler

Types

type Agent

type Agent interface {
	WriteMsg(msg interface{})
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	Close()
	Destroy()
	UserData() interface{}
	SetUserData(data interface{})
}

type ChannelRemote

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

func NewChannelRemote

func NewChannelRemote(conn *Connector) *ChannelRemote

func (*ChannelRemote) Broadcast

func (c *ChannelRemote) Broadcast(ctx context.Context, args *rpc.ArgsGroup, reply *rpc.ReplyGroup) error

Broadcast to all the client connectd with current frontend server.

func (*ChannelRemote) PushMessageByGroup

func (c *ChannelRemote) PushMessageByGroup(ctx context.Context, args *rpc.ArgsGroup, reply *rpc.ReplyGroup) error

Push message to client by uids.

type Connection

type Connection interface {
	OnDisconnect(session *rpc.Session)
}

type Connector

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

func NewConnector

func NewConnector(opts ...Option) *Connector

func (*Connector) Cb

func (c *Connector) Cb(session *rpc.Session, msgId int, msg interface{})

func (*Connector) OnDestroy

func (c *Connector) OnDestroy()

func (*Connector) OnInit

func (c *Connector) OnInit()

func (*Connector) Route

func (c *Connector) Route(f rpc.CustomerRoute)

func (*Connector) Run

func (c *Connector) Run(closeSig chan bool)

func (*Connector) SetConnectionListener

func (c *Connector) SetConnectionListener(conn Connection)

func (*Connector) SetRegisterServiceHandler

func (c *Connector) SetRegisterServiceHandler(r rpc.HandlerRegister)

Register session service

func (*Connector) SetRouter

func (c *Connector) SetRouter(route rpc.RpcRouter)

type Option

type Option func(*Options)

func CertFile

func CertFile(f string) Option

Cert file for https

func HTTPTimeout

func HTTPTimeout(t time.Duration) Option

Timeout for http handshake. Default is 10s

func HeartbeatTimeout

func HeartbeatTimeout(t time.Duration) Option

Heartbeat timeout. Default is 10s. Disconnect if after 2*t

func KeyFile

func KeyFile(f string) Option

Key file for https

func LenMsgLen

func LenMsgLen(num int) Option

Length of message length. Useful for tcp. Option is 1,2,4. Default is 2

func LittleEndian

func LittleEndian(littleEndian bool) Option

Useful for tcp. Default is false

func MaxConnNum

func MaxConnNum(num int) Option

Max connections support. Default is 20000

func MaxMsgLen

func MaxMsgLen(length uint32) Option

Max message length. If a message exceeds the limit, the connection sends a close message to the peer. Default is 4096

func PendingWriteNum

func PendingWriteNum(num int) Option

Length of connection write chan. Default is 200. If pending write too much, it will close connection.

func TCPAddr

func TCPAddr(addr string) Option

Address of tcp server as "host:port"

func WSAddr

func WSAddr(addr string) Option

Address of websocket server as "host:port"

type Options

type Options struct {
	MaxConnNum       int
	PendingWriteNum  int
	MaxMsgLen        uint32
	HeartbeatTimeout time.Duration

	// websocket
	WSAddr      string
	HTTPTimeout time.Duration
	CertFile    string
	KeyFile     string

	// tcp
	TCPAddr      string
	LenMsgLen    int
	LittleEndian bool
}

type SessionRemote

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

func NewSessionRemote

func NewSessionRemote(c *Connector) *SessionRemote

func (*SessionRemote) Bind

func (s *SessionRemote) Bind(ctx context.Context, args *rpc.Args, reply *rpc.Reply) error

func (*SessionRemote) GetSessionCount added in v1.0.1

func (s *SessionRemote) GetSessionCount(ctx context.Context, args *rpc.Args, reply *rpc.Reply) error

func (*SessionRemote) KickBySid

func (s *SessionRemote) KickBySid(ctx context.Context, args *rpc.Args, reply *rpc.Reply) error

func (*SessionRemote) Push

func (s *SessionRemote) Push(ctx context.Context, args *rpc.Args, reply *rpc.Reply) error

func (*SessionRemote) UnBind

func (s *SessionRemote) UnBind(ctx context.Context, args *rpc.Args, reply *rpc.Reply) error

type TimeJob

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

type Timers

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

func NewTimer

func NewTimer() *Timers

func (*Timers) AfterFunc

func (t *Timers) AfterFunc(d time.Duration, cb func()) *timer.Timer

func (*Timers) ClearTimeout

func (t *Timers) ClearTimeout(handler *timer.Timer)

func (*Timers) CronFunc

func (t *Timers) CronFunc(cronExpr *timer.CronExpr, cb func()) *timer.Cron

func (*Timers) RunTimer

func (t *Timers) RunTimer(closeSig chan bool)

Jump to

Keyboard shortcuts

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