Documentation
¶
Index ¶
Constants ¶
const Extended16BitLength = 126
Constant used on the Length field if the length actually has 16 bits.
const Extended64BitLength = 127
Constant used on the Length field if the length actually has 64 bits.
const FinBit = 0x80
Bit used to indicate that this is the last (or only) part of a message.
const LengthIndex = 1
Index of the opcode within a Frame.
const LengthMask = 0x7F
Mask to retrieve the opcode from its byte in the Frame.
const MaskBit = 0x80
Bit used to check whether "Payload data" is masked.
const MaskIndex = 1
Index of the mask bit within a Frame.
const MaskLength = 4
Length of the "Masking-key".
const MinHeaderLength = 2
Minimal length (in bytes) of a message from a WebSocket.
const OpcodeIndex = 0
Index of the opcode within a Frame.
const OpcodeMask = 0x0F
Mask to retrieve the opcode from its byte in the Frame.
const Strict = false
Currently, only ignores if no |Host| was supplied in the header.
const WS_SERVER_ID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
GUID used by every WebSocket server (as specified on the RFC).
Variables ¶
var HeartBeatMessage = []byte{0x80 | byte(Pong), 0x00}
Default message to be used for heart-beats.
Functions ¶
Types ¶
type ClientConnection ¶
type ClientConnection interface { // Send buf through the web-socket, wrapping it into a WebSocket frame and // as text data. Use 'Send' if you need to specify the type. Write(buf []byte) (int, error) // Send buf through the web-socket, wrapping it into a WebSocket frame and // as the specified type. Send(buf []byte, dataType Opcode) error // Send data throught the WebSocket as-is. Shouldn't be used unless you know // what you are doing! SendRaw(buf []byte) error // Requests to close the connection with the client. Close(code CloseReason, reason []byte) error // Release cached memory. Should be used for long-living connections that // occasionally sends really big messages. Flush() }
Ugly (and probably non-convetional) interface that exports the only public functions of connections to clients. None of these are thread-safe. However, since they should only be called from the goroutine handling the client's connection, this shouldn't be an issue...
type CloseReason ¶
type CloseReason uint16
const ( NormalClosure CloseReason = 1000 GoingAway CloseReason = 1001 ProtocolError CloseReason = 1002 InvalidDataType CloseReason = 1003 InconsistentContent CloseReason = 1007 InvalidMessage CloseReason = 1008 MessageTooBig CloseReason = 1009 MissingExtension CloseReason = 1010 UnexpectedError CloseReason = 1011 )
type Context ¶
type Context struct { // Local IP where connections are accept (blank for accepting globally). Ip string // URI for accepting connections (e.g., 'ws://Ip:Port/Uri'). Uri string // Port where the WebSocket will listen to. Cannot be changed after starting // the server. Port int // How many simultaneous connections this server accepts. Anything less or // equal to 0 means unlimited. MaximumConnections int // contains filtered or unexported fields }
func NewContext ¶
Creates a new context. The context may be manually instantiated as well (as long as all public fields are set).
func (*Context) Run ¶
Runs the websocket server and blocks execution until 'Stop' is called. Can (and should) safelly be called from/as a goroutine. If it fails to accept any connection, the error is reported through the supplied channel (if any).
The server signals that it has exited by sending a nil error to the channel.
func (*Context) SetTlsConfig ¶
Set the new TLS configuration. Open connections will still use the old credentials, but new connections will automatically use this new one.
type Opcode ¶
type Opcode uint8
Defines the interpretation of the "Payload data". Only the lowest 4 bits are used.
type Server ¶
type Server interface { // Returns a new instance of this server, passed to the runner. Clone(conn ClientConnection) (Server, error) // Do something with the received message. Offset points to the actual // payload within the WebSocket frame. Do(msg []byte, offset int) error // Called after the connection to this client was closed. Cleanup() }