Skip to content

pdf/websocketrwc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc License-MIT

websocketrwc

-- import "github.com/pdf/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.

About

Golang package that wraps Gorilla websocket in an io.ReadWriteCloser interface

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages