ws

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WRITE_TIMEOUT = 1 * time.Second
)

Variables

This section is empty.

Functions

func Serve

func Serve[T any](ctx context.Context, socketPath string, protocol Protocol[T], server Server[T]) error

Types

type Client

type Client[T any] interface {
	Ctx() context.Context
	P.Pipe[T]
	Close() error
}

func Connect

func Connect[T any](ctx context.Context, protocol Protocol[T], socketPath string) (Client[T], error)

type Protocol

type Protocol[T any] interface {
	Encode(data T) ([]byte, error)
	Decode(data []byte) (T, error)
}
var RawProtocol Protocol[[]byte] = rawProtocol{}

type RawClient

type RawClient Client[[]byte]

type Server

type Server[T any] interface {
	HandleWSClient(client Client[T])
}

type WSClient

type WSClient[T any] struct {
	util.Lifetime
	Conn *websocket.Conn
	// contains filtered or unexported fields
}

func (*WSClient[T]) Close

func (c *WSClient[T]) Close() error

func (*WSClient[T]) Receive

func (c *WSClient[T]) Receive() <-chan P.Packet[T]

func (*WSClient[T]) Send

func (c *WSClient[T]) Send(data T) error

type WSServer

type WSServer[T any] struct {
	// contains filtered or unexported fields
}

func (*WSServer[T]) ServeHTTP

func (ws *WSServer[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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