network

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LittleEndian = false
)
View Source
const (
	MaxMsgLen = 1024 * 1024 * 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	Run()
	OnClose()
}

type Conn

type Conn interface {
	ReadMsg() (int, []byte, error)
	WriteMsg(args *common.TWSData) error
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	Close()
	Destroy()
}

type Processor

type Processor interface {
	// must goroutine safe
	Route(msg interface{}, userData interface{}) error
	// must goroutine safe
	Unmarshal(data []byte) (interface{}, error)
	UnmarshalMul(nType int, data []byte) (interface{}, error)
	// must goroutine safe
	Marshal(msg interface{}) (*common.TWSData, error)
	// Whether to use packet mode for packing/unpacking
	UsePacketMode() bool
}

type WSClient

type WSClient struct {
	sync.Mutex
	Addr             string
	ConnNum          int
	ConnectInterval  time.Duration
	PendingWriteNum  int
	MaxMsgLen        uint32
	HandshakeTimeout time.Duration
	AutoReconnect    bool
	NewAgent         func(*WSConn) Agent
	// contains filtered or unexported fields
}

WSClient just for client dial to websocket server

func (*WSClient) Close

func (client *WSClient) Close()

Close initiates the shutdown process for the client.

func (*WSClient) Start

func (client *WSClient) Start()

Start initializes and starts the WebSocket client.

type WSConn

type WSConn struct {
	sync.Mutex

	//add by hl
	SessionId string
	AppParam  common.TAppParam
	AppURL    string
	CookieVal string
	// contains filtered or unexported fields
}

func (*WSConn) Close

func (wsConn *WSConn) Close()

Close initiates a graceful shutdown of the connection.

func (*WSConn) Destroy

func (wsConn *WSConn) Destroy()

Destroy cleanly closes the connection.

func (*WSConn) LocalAddr

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

LocalAddr returns the local network address.

func (*WSConn) ReadMsg

func (wsConn *WSConn) ReadMsg() (int, []byte, error)

ReadMsg reads a message from the websocket connection.(goroutine not safe) goroutine not safe.

func (*WSConn) RemoteAddr

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

RemoteAddr returns the remote network address.

func (*WSConn) WriteMsg

func (wsConn *WSConn) WriteMsg(args *common.TWSData) error

WriteMsg writes a message to the websocket connection.(Args must not be modified by the others goroutines) args must not be modified by the others goroutines.

type WSHandler

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

func (*WSHandler) ServeHTTP

func (handler *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles HTTP requests and upgrades them to WebSocket if the request is valid.

type WSServer

type WSServer struct {
	Addr            string
	MaxConnNum      int
	PendingWriteNum int
	MaxMsgLen       uint32
	HTTPTimeout     time.Duration
	CertFile        string
	KeyFile         string
	NewAgent        func(*WSConn) Agent
	// contains filtered or unexported fields
}

func (*WSServer) Close

func (server *WSServer) Close()

Close shuts down the WebSocket server and closes all active connections.

func (*WSServer) Start

func (server *WSServer) Start()

Start initializes and starts the WebSocket server.

type WebsocketConnSet

type WebsocketConnSet map[*websocket.Conn]struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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