wsHub

package module
v0.0.0-...-a9f4ed6 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2014 License: MIT Imports: 6 Imported by: 0

README

wsHub

A websocket connection hub

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TimeoutErr = errors.New("Timeout hit before messaged recieved") //Is it best to use an error for the timeout
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(w http.ResponseWriter, r *http.Request, bufSize ...int) (*Client, error)

Creates a new ws client to broadcast to TODO: Read only option

func NewLeader

func NewLeader(w http.ResponseWriter, r *http.Request, bufSize ...int) (*Client, error)

func (*Client) Read

func (c *Client) Read() ([]byte, error)

Read a message from the websocket connection, wait untill you get a message

func (*Client) ReadJSON

func (c *Client) ReadJSON(bean interface{}) error

func (*Client) ReadString

func (c *Client) ReadString() (string, error)

func (*Client) ReadTimeout

func (c *Client) ReadTimeout(timeout time.Duration) ([]byte, error)

Read a message, but give up after a given timeout returns nil if the timeout is hit

func (*Client) Start

func (c *Client) Start()

Starts the client listening handler to write messages to

func (*Client) Write

func (c *Client) Write(msg []byte)

Write a message back to the client

func (*Client) WriteJSON

func (c *Client) WriteJSON(msg interface{})

Write a JSON message to the client

func (*Client) WriteString

func (c *Client) WriteString(msg string)

Write a string message to the client

type WsHub

type WsHub struct {
	// contains filtered or unexported fields
}

Central communitaion struct

func NewHub

func NewHub() *WsHub

Create new hub

func (*WsHub) Broadcast

func (h *WsHub) Broadcast(c *Client, msg []byte)

Broadcast a message to all connected clients

func (*WsHub) BroadcastJSON

func (h *WsHub) BroadcastJSON(c *Client, msg interface{})

func (*WsHub) RegisterClient

func (h *WsHub) RegisterClient(c *Client)

Register a given client object

func (*WsHub) Run

func (h *WsHub) Run()

Run the hub (most likely in its own goroutine) Handles all communitaion between connected clients

func (*WsHub) Stop

func (h *WsHub) Stop()

Kill the running hub

func (*WsHub) UnregisterClient

func (h *WsHub) UnregisterClient(c *Client)

Unregister a given client

Directories

Path Synopsis
examples
chat
A simple chat program leveraging websockets and the wsHub package
A simple chat program leveraging websockets and the wsHub package

Jump to

Keyboard shortcuts

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