network

package
v0.0.0-...-1ca43b3 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const DefaultReadTimeout = 2 * time.Second
View Source
const DefaultWriteBuff = 1024
View Source
const DefaultWriteTimeout = 2 * time.Second

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnCallback

type ConnCallback interface {
	OnConnect(*WrapConnection) bool
	OnMessage(*WrapConnection, *Message) bool
	OnClose(*WrapConnection)
}

type Connection

type Connection struct {
	Mu            sync.Mutex
	WebsocketConn *websocket.Conn
	// contains filtered or unexported fields
}

func (*Connection) Close

func (c *Connection) Close()

func (*Connection) InitCloseHandler

func (c *Connection) InitCloseHandler()

func (*Connection) ReadMessage

func (c *Connection) ReadMessage() (messageType int, p []byte, err error)

func (*Connection) RegisterCloseFunctor

func (c *Connection) RegisterCloseFunctor(name string, function *Functor)

func (*Connection) RegisterConnectFunctor

func (c *Connection) RegisterConnectFunctor(name string, function *Functor)

func (*Connection) RemoteAddr

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

func (*Connection) WriteMessage

func (c *Connection) WriteMessage(messageType int, data []byte) error

type Functor

type Functor struct {
	Func func(code int, text string, args ...interface{}) error
	Args []interface{}
}

type Message

type Message struct {
	MsgType int
	Data    []byte
}

type WrapConnection

type WrapConnection struct {
	Connection     *Connection
	PlayerId       string
	IsClosed       atomic.Bool
	ReadTimeout    time.Duration
	WriteTimeout   time.Duration
	LastActiveTime *atomic.Int64
	// contains filtered or unexported fields
}

func NewWrapConn

func NewWrapConn(conn *websocket.Conn, playerId string, server ConnCallback) *WrapConnection

func (*WrapConnection) AddOnCloseHandler

func (wc *WrapConnection) AddOnCloseHandler(name string, function *Functor)

func (*WrapConnection) AddOnConnectHandler

func (wc *WrapConnection) AddOnConnectHandler(name string, function *Functor)

func (*WrapConnection) Close

func (wc *WrapConnection) Close()

func (*WrapConnection) OnConnect

func (wc *WrapConnection) OnConnect()

func (*WrapConnection) Read

func (wc *WrapConnection) Read() (messageType int, p []byte, err error)

func (*WrapConnection) Run

func (wc *WrapConnection) Run()

func (*WrapConnection) UpdateLastActiveTime

func (wc *WrapConnection) UpdateLastActiveTime(timestamp int64)

func (*WrapConnection) Write

func (wc *WrapConnection) Write(messageType int, data []byte) (err error)

Jump to

Keyboard shortcuts

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