websocket

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ServerTypeEnum = []string{"normal", "echo"}

ServerTypeEnum the type of websocket server

Functions

This section is empty.

Types

type Client

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

Client websocket client

func NewWsClient

func NewWsClient(serverPath string, app *grumble.App) *Client

NewWsClient the websocket client constructor

func (*Client) CloseConnection

func (c *Client) CloseConnection() error

CloseConnection close the websocket connection

func (*Client) Connection

func (c *Client) Connection() error

Connection to websocket server

func (*Client) HandlerTextReceive

func (c *Client) HandlerTextReceive()

HandlerTextReceive handler the text message from websocket server to print on cli

func (*Client) HistoryOfReceive

func (c *Client) HistoryOfReceive() []TextMessage

HistoryOfReceive the history of the received messages

func (*Client) HistoryOfSend

func (c *Client) HistoryOfSend() []TextMessage

HistoryOfSend the history of the send messages

func (*Client) SendText

func (c *Client) SendText(msg string) error

SendText send a text message to server

func (*Client) ServerPath

func (c *Client) ServerPath() string

ServerPath return server path which is the client to connection

type Server

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

Server websocket socket server

func NewWsServer

func NewWsServer(path string, port int, serverType ServerType, app *grumble.App) *Server

NewWsServer the constructor of Server

func (*Server) Clients

func (s *Server) Clients() []string

Clients return the list of all client

func (*Server) HistoryOfReceive

func (s *Server) HistoryOfReceive() []TextMessage

HistoryOfReceive the history of the received messages

func (*Server) HistoryOfSend

func (s *Server) HistoryOfSend() []TextMessage

HistoryOfSend the history of the send messages

func (*Server) Port

func (s *Server) Port() int

Port return the server port

func (*Server) Run

func (s *Server) Run(stop chan struct{})

Run start the server

func (*Server) SendText

func (s *Server) SendText(remoteAddr string, msg string) error

SendText send text message to a connection

func (*Server) SendTextToAllConnection

func (s *Server) SendTextToAllConnection(msg string) error

SendTextToAllConnection send text message to all connection

func (*Server) ServerPath

func (s *Server) ServerPath() string

ServerPath return the server path

func (*Server) URL

func (s *Server) URL() string

URL return the url

type ServerType

type ServerType int

ServerType the type of websocket server

const (
	// Normal normal websocket server
	Normal ServerType = iota
	// Echo echo server
	Echo
)

func ToServerType

func ToServerType(t string) ServerType

ToServerType string to ServerType

func (ServerType) ToString

func (st ServerType) ToString() string

ToString return the type of websocket server

type TextMessage

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

TextMessage the text-message object

func NewReceiveMessage

func NewReceiveMessage(conn *websocket.Conn, msg string) TextMessage

NewReceiveMessage TextMessage constructor for receive message

func NewSendMessage

func NewSendMessage(conn *websocket.Conn, msg string) TextMessage

NewSendMessage TextMessage constructor for send message

func (TextMessage) Message

func (h TextMessage) Message() string

Message return the context of message

func (TextMessage) SourceAddress

func (h TextMessage) SourceAddress() string

SourceAddress return the source address of message

func (TextMessage) TargetAddress

func (h TextMessage) TargetAddress() string

TargetAddress return the target address of message

func (TextMessage) Time

func (h TextMessage) Time() time.Time

Time return the time of message

func (TextMessage) TimeString

func (h TextMessage) TimeString() string

TimeString return the time of message

func (TextMessage) ToString

func (h TextMessage) ToString() string

ToString return the message info

Jump to

Keyboard shortcuts

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