Documentation ¶
Overview ¶
Package websocket 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 DialError
- type Draft75Handler
- type Handler
- type ProtocolError
- type WebSocketAddr
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadScheme = os.ErrorString("bad scheme") ErrBadStatus = &ProtocolError{"bad status"} ErrBadUpgrade = &ProtocolError{"missing or bad upgrade"} ErrBadWebSocketOrigin = &ProtocolError{"missing or bad WebSocket-Origin"} ErrBadWebSocketLocation = &ProtocolError{"missing or bad WebSocket-Location"} ErrBadWebSocketProtocol = &ProtocolError{"missing or bad WebSocket-Protocol"} ErrChallengeResponse = &ProtocolError{"mismatch challenge/response"} )
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 // The initial http Request (for the Server side only). Request *http.Request // 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:
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 ¶
SetWriteTimeout sets the connection's network write timeout in nanoseconds.
type Draft75Handler ¶
type Draft75Handler func(*Conn)
Draft75Handler is an interface to a WebSocket based on the (soon obsolete) draft-hixie-thewebsocketprotocol-75.
func (Draft75Handler) ServeHTTP ¶
func (f Draft75Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements the http.Handler interface for a Web Socket.
type Handler ¶
type Handler func(*Conn)
Handler is an interface to a WebSocket.
A trivial example server:
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.