Documentation ¶
Overview ¶
The websocket package implements a client and server for the Web Socket protocol. The protocol is defined at http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol
Index ¶
- Variables
- type Conn
- func (ws *Conn) Close() os.Error
- func (ws *Conn) LocalAddr() net.Addr
- func (ws *Conn) Read(msg []byte) (n int, err os.Error)
- func (ws *Conn) RemoteAddr() net.Addr
- func (ws *Conn) SetReadTimeout(nsec int64) os.Error
- func (ws *Conn) SetTimeout(nsec int64) os.Error
- func (ws *Conn) SetWriteTimeout(nsec int64) os.Error
- func (ws *Conn) Write(msg []byte) (n int, err os.Error)
- type Handler
- type ProtocolError
- type WebSocketAddr
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadStatus = &ProtocolError{"bad status"} ErrNoUpgrade = &ProtocolError{"no upgrade"} ErrBadUpgrade = &ProtocolError{"bad upgrade"} ErrNoWebSocketOrigin = &ProtocolError{"no WebSocket-Origin"} ErrBadWebSocketOrigin = &ProtocolError{"bad WebSocket-Origin"} ErrNoWebSocketLocation = &ProtocolError{"no WebSocket-Location"} ErrBadWebSocketLocation = &ProtocolError{"bad WebSocket-Location"} ErrNoWebSocketProtocol = &ProtocolError{"no WebSocket-Protocol"} ErrBadWebSocketProtocol = &ProtocolError{"bad WebSocket-Protocol"} )
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct { // The origin URI for the Web Socket. Origin string // The location URI for the Web Socket. Location string // The subprotocol for the Web Socket. Protocol string // contains filtered or unexported fields }
Conn is a channel to communicate to a Web Socket. It implements the net.Conn interface.
func Dial ¶
Dial opens a new client connection to a Web Socket. A trivial example client is:
package main
import (
"websocket" "strings"
)
func main() { ws, err := websocket.Dial("ws://localhost/ws", "", "http://localhost/"); if err != nil { panic("Dial: ", err.String()) } if _, err := ws.Write([]byte("hello, world!\n")); err != nil { panic("Write: ", err.String()) } var msg = make([]byte, 512); if n, err := ws.Read(msg); err != nil { panic("Read: ", err.String()) } // use msg[0:n] }
func (*Conn) RemoteAddr ¶
RemoteAddr returns the WebSocket locations for the connection.
func (*Conn) SetReadTimeout ¶
SetReadTimeout sets the connection's network read timeout in nanoseconds.
func (*Conn) SetTimeout ¶
SetTimeout sets the connection's network timeout in nanoseconds.
func (*Conn) SetWriteTimeout ¶
SeWritetTimeout sets the connection's network write timeout in nanoseconds.
type Handler ¶
type Handler func(*Conn)
Handler is an interface to a WebSocket. A trivial example server is:
package main
import (
"http" "io" "websocket"
)
// Echo the data received on the Web Socket.
func EchoServer(ws *websocket.Conn) { io.Copy(ws, ws); }
func main() { http.Handle("/echo", websocket.Handler(EchoServer)); err := http.ListenAndServe(":12345", nil); if err != nil { panic("ListenAndServe: ", err.String()) } }
type ProtocolError ¶
type ProtocolError struct {
os.ErrorString
}
type WebSocketAddr ¶
type WebSocketAddr string
WebSocketAddr is an implementation of net.Addr for Web Sockets.
func (WebSocketAddr) Network ¶
func (addr WebSocketAddr) Network() string
Network returns the network type for a Web Socket, "websocket".
func (WebSocketAddr) String ¶
func (addr WebSocketAddr) String() string
String returns the network address for a Web Socket.