websock

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpHandler

type HttpHandler struct {
	Path           string
	Method         string
	MessageHandler func(http.ResponseWriter, *http.Request)
}

type Message

type Message struct {
	MsgType int
	Message []byte
}

type StaticFileHandler

type StaticFileHandler struct {
	PathPrefix  string
	Folder      string
	CertsFolder string
}

type WSClient

type WSClient struct {
	OnConnect    func(*websocket.Conn)
	OnDisconnect func(*websocket.Conn)

	OnReadMessage  func(message *Message)
	OnWriteMessage func(message *Message)

	OnError func(error)
	// contains filtered or unexported fields
}

func (*WSClient) Connect

func (w *WSClient) Connect(scheme string, address string, path string) error

func (*WSClient) Disconnect

func (w *WSClient) Disconnect()

func (*WSClient) Send

func (w *WSClient) Send(msgType int, message []byte)

func (*WSClient) SendObject

func (w *WSClient) SendObject(message interface{})

type WSContext

type WSContext struct {
	MessageHandler func(client *WSSession, message interface{})
	MessageType    reflect.Type
}

type WSHandler

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

func NewWSHandler

func NewWSHandler(textMessageHandler WSMessageHandler, binaryMessageHandler WSMessageHandler) *WSHandler

NewWSHandler NewHandler create web socket handler

func (*WSHandler) AddReceiveMessageHandler

func (m *WSHandler) AddReceiveMessageHandler(protocolId string, wsContext *WSContext) map[string]*WSContext

func (*WSHandler) AddReceiveMessageHandlers

func (m *WSHandler) AddReceiveMessageHandlers(handlers map[string]*WSContext) map[string]*WSContext

type WSMessageHandler added in v0.0.3

type WSMessageHandler func(session *WSSession, message []byte)

type WSServer

type WSServer struct {

	// on connect
	OnConnect func(*WSSession)

	// on disconnect
	OnDisconnect func(*WSSession)
	// contains filtered or unexported fields
}

WSServer WebSocket Server

func NewWSServer

func NewWSServer(addr string, wsHandler *WSHandler,
	staticFile *StaticFileHandler, httpHandlers ...*HttpHandler) *WSServer

func (*WSServer) MsgHandler

func (s *WSServer) MsgHandler(session *WSSession, messageType int, message []byte)

func (*WSServer) Run

func (s *WSServer) Run()

func (*WSServer) RunWithTLS

func (s *WSServer) RunWithTLS(certFile, KeyFile string)

func (*WSServer) Stop

func (s *WSServer) Stop() *WSServer

type WSSession

type WSSession struct {
	// network
	Server *WSServer

	// The web socket connection.
	Conn *websocket.Conn

	// user context
	UserContext interface{}
	// contains filtered or unexported fields
}

func (*WSSession) Close

func (w *WSSession) Close()

func (*WSSession) Send

func (w *WSSession) Send(msgType int, message []byte)

func (*WSSession) SendJson

func (w *WSSession) SendJson(message interface{})

func (*WSSession) SendMessage

func (w *WSSession) SendMessage(message *Message)

func (*WSSession) SendString

func (w *WSSession) SendString(message string)

Jump to

Keyboard shortcuts

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