ws

package
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2015 License: BSD-2-Clause Imports: 7 Imported by: 0

README

Pivo/Websocket

Websocket connector for the Pivo package

Getting started

Documentation
Installation

Install the Pivo library using the following go command.

$ go get gopkg.in/pivo.v2
Dependencies

The Pivo/Websocket connector depends on the Gorilla Websocket library.

$ go get github.com/gorilla/websocket

License

Use of this source code is governed by a Simplified BSD license that can be found in the LICENSE file.

Documentation

Overview

Package ws implements the Pivo/Websocket connector.

Index

Constants

View Source
const DefaultPingTimeout = 60

Default ping timeout value in seconds

View Source
const DefaultPortBufferSize = 64

Default port buffer size

View Source
const DefaultReadBufferSize = 1024

Default read buffer size

View Source
const DefaultWriteBufferSize = 1024

Default write buffer size

View Source
const DefaultWriteTimeout = 10

Default write timeout value in seconds

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// Ping timeout
	PingTimeout time.Duration

	// Write timeout
	WriteTimeout time.Duration

	// Port buffer size
	PortBufferSize int

	// Those settings are only used by upgraders.
	// See http://godoc.org/github.com/gorilla/websocket#Upgrader
	CheckOrigin     func(*http.Request) bool
	ReadBufferSize  int
	WriteBufferSize int
	// contains filtered or unexported fields
}

Conn specifies parameters for this connector.

func DefaultConn

func DefaultConn() *Conn

DefaultConn instantiate a connector with default settings.

func (*Conn) BinaryMessage

func (c *Conn) BinaryMessage(bin []byte) *pivo.Message

BinaryMessage formats a binary message and returns a pointer to it.

func (*Conn) Close

func (c *Conn) Close(err error) error

Close sends a closure message to the remote end.

func (*Conn) Dial

func (c *Conn) Dial(url string, h http.Header) (*Conn, *http.Response, error)

Dial opens a connection to the given URL with the provided header.

func (*Conn) Protocol

func (c *Conn) Protocol() string

Protocol returns the name of the Pivo transport protocol used.

func (*Conn) Receiver

func (c *Conn) Receiver(rc pivo.OnReadCloser) error

Receiver is an event loop that either calls OnCloser if the connection has terminated or OnReader when data has been read from the socket. Reading data from the socket or keeping it alive will not work unless that function is spinning in a goroutine.

Receiver returns whatever error the OnCloser did return.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns the IP address of the remote end.

func (*Conn) Send

func (c *Conn) Send(m *pivo.Message) error

Send pushes the given message through the port buffer. pivo.ErrPortBufferIsFull is thrown either if the port buffer is not open or if it has reached it's buffer size.

func (*Conn) Sender

func (c *Conn) Sender() error

Sender reads messages from the port buffer and write them to the socket. Sending data or keeping the socket open will not be possible without spinning that function in a goroutine.

func (*Conn) TextMessage

func (c *Conn) TextMessage(text string) *pivo.Message

TextMessage formats a text message and returns a pointer to it.

func (*Conn) Upgrade

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

Upgrade tries to upgrade an HTTP request to a Websocket session.

Directories

Path Synopsis
bin

Jump to

Keyboard shortcuts

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