server

package
v0.0.0-...-0454a22 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeadPackSizeLen = 4
)

Variables

This section is empty.

Functions

func RunTCPServer

func RunTCPServer(opts *Options) error

func RunWebsocketServer

func RunWebsocketServer(opts *Options) error

Types

type Account

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

func NewAccount

func NewAccount(conn Conn) *Account

func (*Account) ID

func (acc *Account) ID() string

type Accounts

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

func NewAccounts

func NewAccounts() *Accounts

func (*Accounts) AddAccount

func (as *Accounts) AddAccount(acc *Account)

func (*Accounts) RemoveAccount

func (as *Accounts) RemoveAccount(id string)

type AuthOptions

type AuthOptions struct {
	Timeout  time.Duration
	Password string
}

type Conn

type Conn interface {
	ConnID() string

	LocalAddr() net.Addr

	RemoteAddr() net.Addr

	Accept()

	Close() error

	Closed() bool

	Write(data []byte) error

	Server() Server
}

type Handler

type Handler interface {
	CreateConn()
	Close()
	ReadData(data []byte) error
}

type Options

type Options struct {
	Websocket       *WebsocketOptions
	PingInterval    time.Duration
	MaxPingOutTimes int
	Auth            *AuthOptions
}

func NewOptions

func NewOptions() *Options

type Packet

type Packet struct{}

func (*Packet) Marshal

func (*Packet) Marshal(code types.OpCode, payload interface{}) ([]byte, error)

func (*Packet) Unmarshal

func (*Packet) Unmarshal(payload []byte) (types.OpCode, interface{}, error)

type ReadHandler

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

func NewReadHandler

func NewReadHandler(c Conn) *ReadHandler

func (*ReadHandler) Close

func (r *ReadHandler) Close()

func (*ReadHandler) CreateConn

func (r *ReadHandler) CreateConn()

func (*ReadHandler) ReadData

func (r *ReadHandler) ReadData(data []byte) (err error)

type Server

type Server interface {
	Options() *Options
}

type Subscribe

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

func NewSubscribe

func NewSubscribe() *Subscribe

func (*Subscribe) Subscribe

func (s *Subscribe) Subscribe(subsName string) *Topic

type TCPConn

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

func NewTCPConn

func NewTCPConn(rw net.Conn, srv Server) *TCPConn

func (*TCPConn) Accept

func (c *TCPConn) Accept()

func (*TCPConn) Close

func (c *TCPConn) Close() error

func (*TCPConn) Closed

func (c *TCPConn) Closed() bool

func (*TCPConn) ConnID

func (c *TCPConn) ConnID() string

func (*TCPConn) LocalAddr

func (c *TCPConn) LocalAddr() net.Addr

func (*TCPConn) RemoteAddr

func (c *TCPConn) RemoteAddr() net.Addr

func (*TCPConn) Server

func (c *TCPConn) Server() Server

func (*TCPConn) Write

func (c *TCPConn) Write(data []byte) error

type TCPServer

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

func (*TCPServer) ListenAndServe

func (srv *TCPServer) ListenAndServe() error

func (*TCPServer) Options

func (srv *TCPServer) Options() *Options

type Topic

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

func NewTopic

func NewTopic(name string) *Topic

func (*Topic) BroadcastLoop

func (t *Topic) BroadcastLoop()

func (*Topic) HaveAccount

func (t *Topic) HaveAccount() (exists bool)

func (*Topic) Subscribe

func (t *Topic) Subscribe(acc *Account)

func (*Topic) UnSubscribe

func (t *Topic) UnSubscribe(id interface{})

type Topics

type Topics struct {
	sync.Map
	sync.Mutex
}

func (*Topics) GetTopicForce

func (t *Topics) GetTopicForce(name string) *Topic

func (*Topics) RemoveTopic

func (t *Topics) RemoveTopic(name string)

type WebsocketConn

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

func NewWebsocketConn

func NewWebsocketConn(conn *websocket.Conn, srv Server) *WebsocketConn

func (*WebsocketConn) Accept

func (c *WebsocketConn) Accept()

func (*WebsocketConn) Close

func (c *WebsocketConn) Close() error

func (*WebsocketConn) Closed

func (c *WebsocketConn) Closed() bool

func (*WebsocketConn) ConnID

func (c *WebsocketConn) ConnID() string

func (*WebsocketConn) LocalAddr

func (c *WebsocketConn) LocalAddr() net.Addr

func (*WebsocketConn) RemoteAddr

func (c *WebsocketConn) RemoteAddr() net.Addr

func (*WebsocketConn) Server

func (c *WebsocketConn) Server() Server

func (*WebsocketConn) Write

func (c *WebsocketConn) Write(data []byte) error

type WebsocketOptions

type WebsocketOptions struct {
	Addr         string
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

type WebsocketServer

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

func (*WebsocketServer) ListenAndServe

func (srv *WebsocketServer) ListenAndServe() error

func (*WebsocketServer) Options

func (srv *WebsocketServer) Options() *Options

func (*WebsocketServer) ServeHTTP

func (srv *WebsocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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