connection

package
v0.0.0-...-843b749 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package connection implements a websocket connection wrapper with various helper functions.

Index

Constants

View Source
const (
	// MessageBufferSize is the size of each clients message buffer (both directions).
	MessageBufferSize = 32
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	WS                   *websocket.Conn       // The websocket connection itself.
	Joined               time.Time             // The time at which the connection was created.
	Latency              time.Duration         // The current latency of the connection.
	InboundMessageQueue  chan protocol.Message // Inbound message queue - received messages are parked here until removed by a read pump.
	OutboundMessageQueue chan protocol.Message // Outbound message queue - messages to be sent are parked here until removed by a write pump.
	UUID                 xid.ID                // A unique ID for this connection.
	// contains filtered or unexported fields
}

Connection is a wrapper for a websocket connection.

func NewConnection

func NewConnection(wsconn *websocket.Conn) *Connection

NewConnection creates a new connection.

func (*Connection) Close

func (connection *Connection) Close() error

Close closes the connection.

func (*Connection) GetNextInboundMessage

func (connection *Connection) GetNextInboundMessage() protocol.Message

GetNextInboundMessage gets the next message from the inbound message queue. Blocks when the queue is empty, so check the queue's length if you don't want to wait.

func (*Connection) GetNextOutboundMessage

func (connection *Connection) GetNextOutboundMessage() protocol.Message

GetNextOutboundMessage gets the next message from the outbound message queue. Blocks when the queue is empty, so check the queue's length if you don't want to wait.

func (*Connection) ReadMessage

func (connection *Connection) ReadMessage() error

ReadMessage synchronously retreives messages from the websocket.

func (*Connection) SendMessage

func (connection *Connection) SendMessage(message protocol.Message)

SendMessage asynchronously sends a message down the websocket.

func (*Connection) WriteMessage

func (connection *Connection) WriteMessage(message protocol.Message) error

WriteMessage synchronously sends messages down the websocket.

Jump to

Keyboard shortcuts

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