Documentation
¶
Overview ¶
Package websocket provides high-level bindings for the browser's WebSocket API.
These bindings offer a Dial function that returns a regular net.Conn. It can be used similarly to net package.
conn, err := websocket.Dial("ws://localhost/socket") // Blocks until connection is established.
if err != nil {
// handle error
}
buf := make([]byte, 1024)
n, err = conn.Read(buf) // Blocks until a WebSocket frame is received.
doSomethingWithData(buf[:n])
if err != nil {
// handle error
}
_, err = conn.Write([]byte("Hello!"))
// ...
err = conn.Close()
// ...
Index ¶
- type Conn
- func (c *Conn) AddSession(id string, sessionObj interface{}) error
- func (c *Conn) GetSeshKey() string
- func (c *Conn) GetSession(id string) (interface{}, error)
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(b []byte) (n int, err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetSeshKey(seshKey string)
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(b []byte) (n int, err error)
- Bugs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
*websocketjs.WebSocket
// contains filtered or unexported fields
}
conn is a high-level wrapper around WebSocket. It implements net.Conn interface.
func Dial ¶
Dial opens a new WebSocket connection. It will block until the connection is established or fails to connect.
func (*Conn) AddSession ¶
Add session to connection
func (*Conn) GetSession ¶
Return session object
func (*Conn) LocalAddr ¶
LocalAddr would typically return the local network address, but due to limitations in the JavaScript API, it is unable to. Calling this method will cause a panic.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote network address, based on websocket.WebSocket.URL.
func (*Conn) SetDeadline ¶
SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.
A zero value for t means that I/O operations will not time out.
func (*Conn) SetReadDeadline ¶
SetReadDeadline sets the deadline for future Read calls. A zero value for t means Read will not time out.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline sets the deadline for future Write calls. Because our writes do not block, this function is a no-op.
Notes ¶
Bugs ¶
conn.LocalAddr() panics because the underlying JavaScript API has no way of figuring out the local address.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package websocketjs provides low-level bindings for the browser's WebSocket API.
|
Package websocketjs provides low-level bindings for the browser's WebSocket API. |