Categorygithub.com/jaracil/websocket
modulepackage
0.0.0-20160616160344-648d4bd55c0a
Repository: https://github.com/jaracil/websocket.git
Documentation: pkg.go.dev

# README

websocket

Package websocket provides high- and low-level bindings for the browser's WebSocket API.

The high-level bindings act like a regular net.Conn. They can be used as such. For example:

c, err := websocket.Dial("ws://localhost/socket") // Blocks until connection is established
if err != nil { panic(err) }

buf := make([]byte, 1024)
n, err = c.Read(buf) // Blocks until a WebSocket frame is received
if err != nil { panic(err) }
doSomethingWithData(buf[:n])

_, err = c.Write([]byte("Hello!"))
if err != nil { panic(err) }

err = c.Close()
if err != nil { panic(err) }

The low-level bindings use the typical JavaScript idioms.

ws, err := websocket.New("ws://localhost/socket") // Does not block.
if err != nil { panic(err) }

onOpen := func(ev *js.Object) {
	err := ws.Send([]byte("Hello!")) // Send as a binary frame
	err := ws.Send("Hello!")         // Send a text frame
}

ws.AddEventListener("open", false, onOpen)
ws.AddEventListener("message", false, onMessage)
ws.AddEventListener("close", false, onClose)
ws.AddEventListener("error", false, onError)

err = ws.Close()
if err != nil { panic(err) }

# Packages

No description provided by the author

# Functions

Dial opens a new WebSocket connection.
New creates a new low-level WebSocket.

# Constants

Closed means that the connection has been closed or could not be opened.
Closing means that the connection is going through the closing handshake, or the Close() method has been invoked.
Connecting means that the connection has not yet been established.
Open means that the WebSocket connection is established and communication is possible.

# Structs

WebSocket is a low-level convenience wrapper around the browser's WebSocket object.

# Type aliases

ReadyState represents the state that a WebSocket is in.