Categorygithub.com/ArtisanInsight/websocketrwc
modulepackage
0.0.0-20241001174956-8f65de24c02b
Repository: https://github.com/artisaninsight/websocketrwc.git
Documentation: pkg.go.dev

# README

websocketrwc

Fork of https://github.com/pdf/websocketrwc/tree/master Forked so we can add a client Dial method

-- import "github.com/artisaninsight/websocketrwc"

Package websocketrwc wraps Gorilla websocket in an io.ReadWriteCloser compatible interface, allowing it to be used as a net/rpc or similar connection. Only the server side is currently implemented.

Usage

var (
	// ErrClosing is returned for operations during close phase.
	ErrClosing = errors.New(`Closing`)
	// DefaultUpgrader will be used if a nil upgrader is passed to Upgrade().
	DefaultUpgrader = &websocket.Upgrader{
		HandshakeTimeout:  defaultHandshakeTimeout,
		ReadBufferSize:    defaultBufferSize,
		WriteBufferSize:   defaultBufferSize,
		EnableCompression: true,
		CheckOrigin:       func(r *http.Request) bool { return true },
	}
	// WriteTimeout determines the period of time a write will wait to complete
	// before producing an error.
	WriteTimeout = 10 * time.Second
	// PongTimeout determines the period of time a connection will wait for a
	// Pong response to Pings sent to the client.
	PongTimeout = 60 * time.Second
	// PingInterval determins the interval at which Pings are sent to the
	// client.
	PingInterval = (PongTimeout * 9) / 10
)

type Conn

type Conn struct {
}

Conn wraps gorilla websocket to provide io.ReadWriteCloser.

func Upgrade

func Upgrade(w http.ResponseWriter, r *http.Request, h http.Header, upgrader *websocket.Upgrader) (*Conn, error)

Upgrade a HTTP connection.

func (*Conn) Close

func (c *Conn) Close() error

Close implements io.Closer and closes the underlying connection.

func (*Conn) Read

func (c *Conn) Read(p []byte) (n int, err error)

Read implements io.Reader by wrapping websocket messages in a buffer.

func (*Conn) Write

func (c *Conn) Write(p []byte) (n int, err error)

Write implements io.Writer and sends binary messages only.

# Functions

No description provided by the author
Upgrade a HTTP connection to return the wrapped Conn.

# Variables

DefaultUpgrader will be used if a nil upgrader is passed to Upgrade().
ErrClosing is returned for operations during close phase.
PingInterval determines the interval at which Pings are sent to the client.
PongTimeout determines the period of time a connection will wait for a Pong response to Pings sent to the client.
WriteTimeout determines the period of time a write will wait to complete before producing an error.

# Structs

Conn wraps gorilla websocket to provide io.ReadWriteCloser.