network

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(conn Conn, mgr *Mgr) *Client

func (*Client) Close

func (p *Client) Close()

func (*Client) ID

func (p *Client) ID() int32

func (*Client) OnClose

func (p *Client) OnClose()

func (*Client) OnNew

func (p *Client) OnNew()

func (*Client) ReadLoop

func (p *Client) ReadLoop()

func (*Client) SendMsg

func (p *Client) SendMsg(msg proto.Message)

func (*Client) SendRawMsg

func (p *Client) SendRawMsg(msgID uint32, data []byte)

type Conn

type Conn interface {
	ReadMsg() ([]byte, error)
	WriteMsg(args []byte) error
	LocalAddr() net.Addr
	ID() int32
	Close()
}

type Mgr

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

func NewMgr

func NewMgr(wsAddr string, worker service.Worker) *Mgr

func (*Mgr) Close added in v0.0.4

func (p *Mgr) Close()

func (*Mgr) GetSession

func (p *Mgr) GetSession(sesID int32) (Session, bool)

func (*Mgr) ListenAddr added in v0.0.4

func (p *Mgr) ListenAddr() *net.TCPAddr

func (*Mgr) Post

func (p *Mgr) Post(f func())

func (*Mgr) RegisterEvent

func (p *Mgr) RegisterEvent(onNew, onClose func(conn Session))

func (*Mgr) RegisterRawSessionMsgHandler

func (p *Mgr) RegisterRawSessionMsgHandler(msg proto.Message, handler MsgHandler)

func (*Mgr) RegisterSessionMsgHandler

func (p *Mgr) RegisterSessionMsgHandler(cb interface{})

func (*Mgr) Run

func (p *Mgr) Run()

type MsgHandler

type MsgHandler func(client Session, msg proto.Message)

type MsgInfo

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

type Processor

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

func NewProcessor

func NewProcessor() *Processor

func (*Processor) Encode

func (p *Processor) Encode(msgID uint32, data []byte) []byte

func (*Processor) Handle

func (p *Processor) Handle(msg proto.Message, client Session) error

func (*Processor) Marshal

func (p *Processor) Marshal(msg proto.Message) ([]byte, error)

func (*Processor) RegisterSessionMsgHandler

func (p *Processor) RegisterSessionMsgHandler(msg proto.Message, handler MsgHandler)

func (*Processor) SetByteOrder

func (p *Processor) SetByteOrder(littleEndian bool)

func (*Processor) Unmarshal

func (p *Processor) Unmarshal(data []byte) (proto.Message, error)

type Session

type Session interface {
	SendMsg(msg proto.Message)
	SendRawMsg(msgID uint32, data []byte)
	ID() int32
	Close()
}

type WSConn

type WSConn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewWSConn

func NewWSConn(conn *websocket.Conn, connid int32) *WSConn

func (*WSConn) Close

func (p *WSConn) Close()

func (*WSConn) ID

func (p *WSConn) ID() int32

func (*WSConn) LocalAddr

func (p *WSConn) LocalAddr() net.Addr

func (*WSConn) ReadMsg

func (p *WSConn) ReadMsg() ([]byte, error)

func (*WSConn) RemoteAddr

func (p *WSConn) RemoteAddr() net.Addr

func (*WSConn) WriteMsg

func (p *WSConn) WriteMsg(args []byte) error

type WSServer

type WSServer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewWSServer

func NewWSServer(addr string, newClient func(conn Conn) *Client) *WSServer

func (*WSServer) Close added in v0.0.4

func (p *WSServer) Close()

func (*WSServer) ListenAddr added in v0.0.4

func (p *WSServer) ListenAddr() *net.TCPAddr

func (*WSServer) NewConnID

func (p *WSServer) NewConnID() int32

func (*WSServer) ServeHTTP

func (p *WSServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*WSServer) Start

func (p *WSServer) Start() error

Jump to

Keyboard shortcuts

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