Common Lisp Package: CLWS

README:

CLWS - a WebSocket server in Common Lisp

Currently requires SBCL or CCL, but shouldn't be too hard to port to other implementations/platforms supported by iolib.

Supports WebSocket draft protocols 7,8, and 13, and optionally 0.

Doesn't currently support wss: (TLS/SSL) connections, but proxying behind stud or stunnel should work.

Sample usage: Echo Server

First, set up a package:

`lisp (defpackage #:clws-echo (:use :cl :clws))

(in-package #:clws-echo)

`

Then we can start the websockets server, here we use port 12345:

lisp (bordeaux-threads:make-thread (lambda () (run-server 12345)) :name "websockets server")

Next we need to define a 'resource', which we will call /echo (so we will connect with URIs like ws://localhost/echo). To do that, we subclass ws-resource and specialize a few generic functions on that class:

`lisp (defclass echo-resource (ws-resource) ())

(defmethod resource-client-connected ((res echo-resource) client) (format t "got connection on echo server from ~s : ~s~%" (client-host client) (client-port client)) t)

(defmethod resource-client-disconnected ((resource echo-resource) client) (format t "Client disconnected from resource ~A: ~A~%" resource client))

(defmethod resource-received-text ((res echo-resource) client message) (format t "got frame ~s from client ~s" message client) (write-to-client-text client message))

(defmethod resource-received-binary((res echo-resource) client message) (format t "got binary frame ~s from client ~s" (length message) client) (write-to-client-binary client message)) `

Finally, we register the resource with the server, and start a thread to handle messages for that resource:

`lisp (register-global-resource "/echo" (make-instance 'echo-resource) (origin-prefix "http://127.0.0.1" "http://localhost"))

(bordeaux-threads:make-thread (lambda () (run-resource-listener (find-global-resource "/echo"))) :name "resource listener for /echo") `

Configuration variables

  • *protocol-76/00-support*: set to T to enable support for draft-hixie-76/draft-ietf-hybi-00 protocol No longer used by current browsers, and doesn't support binary frames. May go away soon.

  • *max-clients*: maximum number of simultaneous connections allowed, or NIL for no limit

  • *max-read-frame-size*, *max-read-message-size*: maximum 'frame' and 'message' sizes allowed from clients. Malicious clients can cause the server to buffer up to *max-read-message-size* per connection, so these should probably be reduced as much as possible for production servers.

  • *debug-on-server-errors*, *debug-on-resource-errors*: set to T to enter debugger on errors instead of dropping connections, for the server thread and resource handler thread respectively.

Resource handler API

  • register-global-resource (name resource-handler origin-validation-function): Registers resource-handler for the resource name, which should be the abs_path part of a URI, like /foo/bar, origin-validation-function should be a function of one argument which returns true for any origin from which connections will be accepted. See any-origin,origin-prefix,origin-exact. ("Origin" in this case refers to the value of the Origin or Sec-Webcosket-Origin header required to be sent by browsers, specifying the host from which the page was loaded, like http://localhost.)

  • resource-received-text (resource client message): Resource handlers should specialize this generic function to handle text messages from clients. message is a lisp string containing the message from client.

  • resource-received-binary (resource client message): Resource handlers should specialize this generic function to handle binary messages from clients. message is a (vector (unsigned-byte 8)) containing the message from client.

  • resource-client-connected (resource client): Called to notify a resource handler when a client connects. If the handler objects to a particular client for some reason, it can return :reject to close the connection and ignore any already received data from that client.

  • resource-client-disconnected (resource client): Called when a client disconnects.

Sending data to clients

  • write-to-client-text (client message &key frame-size): Send message to client. message should be a CL string or a (simple-array (unsigned-byte 8) (*)) containing a utf-8 encoded string. If frame-size is not nil, message will be broken up into frames of frame-size octets.

  • write-to-clients-text (clients message &key frame-size): Send message to a list of clients. Same as write-to-client-text, but tries to avoid repeated processing (utf-8 encoding, building frames, etc) that can be shared between clients.

  • write-to-client-binary (client message &key frame-size): Send message to client. message should be a (simple-array (unsigned-byte 8) (*)). If frame-size is not nil, message will be broken up into frames of frame-size octets.

  • write-to-clients-binary (clients message &key frame-size): Send message to a list of clients. Same as write-to-client-binary, but tries to avoid repeated processing (utf-8 encoding, building frames, etc) that can be shared between clients.

  • write-to-client-close (client &amp;key (code 1000) message): Send a close message to client. code specifies the 'status code' to be send in the close message (see the websocket spec for valid codes) defaults to 1000, indicating "normal closure". message can be a short string (must utf-8 encode to < 123 octets) describing the reason for closing the connection.

Getting information about connected clients (most of these should be treated as read-only, and any visible setf functions may go away at some point)

  • client-resource-name (client): Name of resource requested by client.

  • client-query-string (client): Query string (the part of the URI after #\? if any) provided by client when connecting. For example if client connects to ws://example.com/test?foo, client-resource-name would return "/test" and client-query-string would return "foo".

  • client-websocket-version (client): Protocol version being used for specified client.

  • client-host (client): IP address of client, as a string.

  • client-port (client): Port from which client connected.

  • client-connection-headers (client): Hash table containing any HTTP headers supplied by client, as a hash table of keywords (:user-agent, :cookie, etc) -> strings.

FUNCTION

Public

FIND-GLOBAL-RESOURCE (NAME)

Returns the resource registered via REGISTER-GLOBAL-RESOURCE with name NAME.

KILL-RESOURCE-LISTENER (RESOURCE)

Terminates a RUN-RESOURCE-LISTENER from another thread.

ORIGIN-EXACT (&REST ORIGINS)

Returns a function that checks whether a given path matches any of the origins passed as arguments exactly.

ORIGIN-PREFIX (&REST PREFIXES)

Returns a function that checks whether a given path matches any of the prefixes passed as arguments.

REGISTER-GLOBAL-RESOURCE (NAME RESOURCE-HANDLER ORIGIN-VALIDATION-FN)

Registers a resource instance where NAME is a path string like '/swank', resource-handler is an instance of WS-RESOURCE, and ORIGIN-VALIDATION-FN is a function that takes an origin string as input and returns T if that origin is allowed to access this resource.

RUN-RESOURCE-LISTENER (RESOURCE)

Runs a resource listener in its own thread indefinitely, calling RESOURCE-CLIENT-DISCONNECTED and RESOURCE-RECEIVED-FRAME as appropriate.

RUN-SERVER (PORT &KEY (ADDR +IPV4-UNSPECIFIED+))

Starts a server on the given PORT and blocks until the server is closed. Intended to run in a dedicated thread (the current one), dubbed the Server Thread. Establishes a socket listener in the current thread. This thread handles all incoming connections, and because of this fact is able to handle far more concurrent connections than it would be able to if it spawned off a new thread for each connection. As such, most of the processing is done on the Server Thread, though most user functions are thread-safe.

UNREGISTER-GLOBAL-RESOURCE (NAME)

Removes the resource registered via REGISTER-GLOBAL-RESOURCE with name NAME.

WRITE-TO-CLIENT-BINARY (CLIENT MESSAGE &KEY FRAME-SIZE)

writes a binary message to client. MESSAGE should either be an octet vector containing data to be sent. If FRAME-SIZE is set, breaks message into frames no larger than FRAME-SIZE octets.

WRITE-TO-CLIENT-CLOSE (CLIENT &KEY (CODE 1000) MESSAGE)

Write a close message to client, and starts closing connection. If set, CODE must be a valid close code for current protocol version, and MESSAGE should be a string that encodes to fewer than 123 octets as UTF8 (it will be ignored otherwise)

WRITE-TO-CLIENT-TEXT (CLIENT MESSAGE &KEY FRAME-SIZE)

writes a text message to client. MESSAGE should either be a string, or an octet vector containing a UTF-8 encoded string. If FRAME-SIZE is set, breaks message into frames no larger than FRAME-SIZE octets.

WRITE-TO-CLIENTS-BINARY (CLIENTS MESSAGE &KEY FRAME-SIZE)

Like WRITE-TO-CLIENT-BINARY but sends the message to all of the CLIENTS. Should be faster than separate calls due to only needing to encode and build frames once.

WRITE-TO-CLIENTS-TEXT (CLIENTS MESSAGE &KEY FRAME-SIZE)

Like WRITE-TO-CLIENT-TEXT but sends the message to all of the clients. Should be faster than separate calls due to only needing to encode and build frames once.

Undocumented

ANY-ORIGIN (O)

Private

%WRITE-TO-CLIENT (CLIENT OCTETS-OR-KEYWORD)

Writes given data to specified client, where OCTETS-OR-KEYWORD is either an octet-vector, or :CLOSE, or a list (:CLOSE CLOSE-OCTETS), where CLOSE-OCTETS is an octet vector to send for close frame. If no close frame is provided, a default close frame will be sent.

CLIENT-DEQUEUE-READ (CLIENT)

Non-blocking call to dequeue a piece of data from a client' read-queue.

CLIENT-DEQUEUE-WRITE (CLIENT)

Non-blocking call to dequeue a piece of data in the write-queue to be sent to the client.

CLIENT-ENQUEUE-READ (CLIENT DATA)

Adds a piece of data to the client's read-queue so that it may be read and processed.

CLIENT-ENQUEUE-WRITE (CLIENT DATA)

Adds data to the client's write-queue and asynchronously send it to the client.

DEQUEUE (QUEUE)

Retrieves the oldest value in QUEUE and returns it as the primary value, and T as secondary value. If the queue is empty, returns NIL as both primary and secondary value.

ENQUEUE (VALUE QUEUE)

Adds VALUE to the end of QUEUE. Returns VALUE.

MAILBOX-COUNT (MAILBOX)

The non-blocking variant of RECEIVE-MESSAGE. Returns two values, the message removed from MAILBOX, and a flag specifying whether a message could be received.

MAILBOX-EMPTY-P (MAILBOX)

Returns true if MAILBOX is currently empty, NIL otherwise.

MAILBOX-LIST-MESSAGES (MAILBOX)

Returns a fresh list containing all the messages in the mailbox. Does not remove messages from the mailbox.

MAILBOX-RECEIVE-MESSAGE (MAILBOX &KEY)

Removes the oldest message from MAILBOX and returns it as the primary value. If MAILBOX is empty waits until a message arrives.

MAILBOX-RECEIVE-MESSAGE-NO-HANG (MAILBOX)

The non-blocking variant of RECEIVE-MESSAGE. Returns two values, the message removed from MAILBOX, and a flag specifying whether a message could be received.

MAILBOX-RECEIVE-PENDING-MESSAGES (MAILBOX &OPTIONAL N)

Removes and returns all (or at most N) currently pending messages from MAILBOX, or returns NIL if no messages are pending. Note: Concurrent threads may be snarfing messages during the run of this function, so even though X,Y appear right next to each other in the result, does not necessarily mean that Y was the message sent right after X.

MAILBOX-SEND-MESSAGE (MAILBOX MESSAGE)

Adds a MESSAGE to MAILBOX. Message can be any object.

MAILBOXP (MAILBOX)

Returns true if MAILBOX is currently empty, NIL otherwise.

MAKE-CHALLENGE-O7 (K &AUX (O7-GUID 258EAFA5-E914-47DA-95CA-C5AB0DC85B11))

Compute the WebSocket opening handshake challenge, according to: http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-07#section-1.3 Test this with the example provided in the above document: (string= (clws::make-challenge-o7 "dGhlIHNhbXBsZSBub25jZQ==") "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=") ..which must return T.

MAKE-DOMAIN-POLICY (&KEY (FROM *) (TO-PORT *))

Generates a very basic cross-domain policy file, used for the WebSocket emulation via Flash. For more information on what that is, see http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html

MAKE-FRAME-FROM-STRING (STRING)

Given a string, returns bytes that can be transmitted to the client as a WebSockets frame.

MAKE-MAILBOX (&KEY NAME INITIAL-CONTENTS)

Returns a new MAILBOX with messages in INITIAL-CONTENTS enqueued.

MAKE-QUEUE (&KEY NAME INITIAL-CONTENTS)

Returns a new QUEUE with NAME and contents of the INITIAL-CONTENTS sequence enqueued.

SPECIAL-CLIENT-WRITE-VALUE-P (VALUE)

Certain values, like :close and :enable-read, are special symbols that may be passed to WRITE-TO-CLIENT or otherwise enqueued on the client's write queue. This predicate returns T if value is one of those special values

TRY-WRITE-CLIENT (CLIENT)

Should only be called on the server thread, attempts to flush some of the data in the write-queue in a non-blocking fashion.

VALID-RESOURCE-P (SERVER RESOURCE)

Returns non-nil if there is a handler registered for the resource of the given name (a string).

Undocumented

%CLIENT-ENQUEUE-WRITE-OR-KILL (FRAME CLIENT)

ADD-READER-TO-CLIENT (CLIENT &KEY (INIT-FUNCTION 'MAYBE-POLICY-FILE))

BINARY-MESSAGE-FOR-PROTOCOL (PROTOCOL MESSAGE &KEY FRAME-SIZE)

BUILD-FRAMES (OPCODE OCTETS FRAME-SIZE)

CALL-WITH-BUFFER-AS-STREAM (BUFFER THUNK)

CLOSE-FRAME-FOR-PROTOCOL (PROTOCOL &KEY (CODE 1000) MESSAGE)

DISCONNECT-CLIENT (CLIENT)

DISPATCH-CONTROL-MESSAGE (CLIENT OPCODE)

DISPATCH-FRAME (CLIENT LENGTH)

DISPATCH-MESSAGE (CLIENT)

DISPATCH-PROTOCOLS (CLIENT)

EXTRACT-KEY (K)

GET-UTF8-STRING-OR-FAIL (CHUNK-BUFFER &KEY SKIP-OCTETS-END)

IGNORE-REMAINING-INPUT (CLIENT)

INVALID-HEADER (CLIENT)

LG (&REST ARGS)

MAKE-CHALLENGE-00 (K1 K2 K3)

MAKE-HANDSHAKE-76 (ORIGIN LOCATION PROTOCOL)

MAKE-LISTENER-HANDLER (SERVER SOCKET SERVER-HOOK)

MATCH-HEADERS (CLIENT)

MATCH-POLICY-FILE (BUFFER)

MATCH-RESOURCE-LINE (BUFFER)

MAYBE-POLICY-FILE (BUFFER)

NEXT-READER-STATE (BUFFER PREDICATE CALLBACK)

OCTET-COUNT-MATCHER (N)

OCTET-PATTERN-MATCHER (OCTETS &OPTIONAL MAX-OCTETS)

PONG-FRAME-FOR-PROTOCOL (PROTOCOL BODY)

PROTOCOL-13-PARSE-HEADERS (CLIENT)

PROTOCOL-7+-EXTENDED-LENGTH (CLIENT OCTETS MASKED)

PROTOCOL-7+-HANDSHAKE (CLIENT VERSION-STRING ORIGIN-KEY)

PROTOCOL-7+-READ-FRAME (CLIENT LENGTH MASK)

PROTOCOL-7+-READ-MASK (CLIENT LENGTH)

PROTOCOL-7+-START-FRAME (CLIENT)

PROTOCOL-7-PARSE-HEADERS (CLIENT)

PROTOCOL-76/00-FRAME-START (CLIENT)

PROTOCOL-76/00-NONCE (CLIENT)

PROTOCOL-76/00-READ-BINARY-FRAME (CLIENT)

PROTOCOL-76/00-READ-TEXT-FRAME (CLIENT)

PROTOCOL-8-PARSE-HEADERS (CLIENT)

SEND-ERROR-AND-CLOSE (CLIENT MESSAGE)

TEXT-MESSAGE-FOR-PROTOCOL (PROTOCOL MESSAGE &KEY FRAME-SIZE)

UNSUPPORTED-PROTOCOL-VERSION (CLIENT)

MACRO

Private

Undocumented

WITH-BUFFER-AS-STREAM ((BUFFER STREAM) &BODY BODY)

GENERIC-FUNCTION

Public

CALL-ON-RESOURCE-THREAD (RESOURCE FN)

Funcalls FN on the resource thread of RESOURCE.

RESOURCE-ACCEPT-CONNECTION (RES RESOURCE-NAME HEADERS CLIENT)

Decides whether to accept a connection and returns values to process the connection further. Defaults to accepting all connections and using the default mailbox and origin, so most resources shouldn't need to define a method. Passed values - RES is the instance of ws-resource - RESOURCE-NAME is the resource name requested by the client (string) - HEADERS is the hash table of headers from the client - client is the instance of client Returns values 1. NIL if the connection should be rejected, or non-nil otherwise 2. Concurrent mailbox in which to place messages received from the client, or NIL for default 3. origin from which to claim this resource is responding, or NIL for default. 4. handshake-resource or NIL for default 5. protocol or NIL for default Most of the time this function will just return true for the first value to accept the connection, and nil for the other values. Note that the connection is not fully established yet, so this function should not try to send anything to the client, see resource-client-connected for that. This function may be called from a different thread than most resource functions, so methods should be careful about accessing shared data, and should avoid blocking for extended periods.

RESOURCE-CLIENT-CONNECTED (RESOURCE CLIENT)

Called when a client finishes connecting to a WebSockets resource, and data can be sent to the client. Methods can return :reject to immediately close the connection and ignore any already received data from this client.

RESOURCE-CLIENT-DISCONNECTED (RESOURCE CLIENT)

Called when a client disconnected from a WebSockets resource.

RESOURCE-RECEIVED-BINARY (RESOURCE CLIENT MESSAGE)

Called when a client sent a binary message to a WebSockets resource.

RESOURCE-RECEIVED-TEXT (RESOURCE CLIENT MESSAGE)

Called when a client sent a text message to a WebSockets resource.

SEND-CUSTOM-MESSAGE-TO-RESOURCE (RESOURCE MESSAGE)

Thread-safe way to pass a message to the resource listener. Any message passed with this function will result in RESOURCE-RECEIVED-CUSTOM-MESSAGE being called on the resource thread with the second argument of this function.

Private

CLIENT-DISABLE-HANDLER (CLIENT &KEY READ WRITE ERROR)

Stop listening for READ, WRITE, or ERROR events on the socket for the given client object.

CLIENT-DISCONNECT (CLIENT &KEY READ WRITE CLOSE ABORT)

Shutdown 1 or both sides of a connection, close it if both sides shutdown

CLIENT-ENABLE-HANDLER (CLIENT &KEY READ WRITE ERROR)

Enables the read, write, or error handler for a a client. Once a read handler is set up, the client can handle the handshake coming in from the client.

RESOURCE-RECEIVED-CUSTOM-MESSAGE (RESOURCE MESSAGE)

Called on the resource listener thread when a client is passed an arbitrary message via SEND-CUSTOM-MESSAGE-TO-RESOURCE.

SERVER-CLIENT-COUNT (SERVER)

Returns number the server's clients.

SERVER-LIST-CLIENTS (SERVER)

Returns a list of the server's clients.

Undocumented

%GET-CHUNKS (CB)

ADD-CHUNK (CB VECTOR START END)

ADD-CHUNKS (CB MORE)

BUFFER-COUNT (BUFFER)

CLIENT-ERROR-ACTIVE (CLIENT)

CLIENT-READER-ACTIVE (CLIENT)

CLIENT-WRITER-ACTIVE (CLIENT)

GET-OCTET-VECTOR (CB)

GET-UTF8-STRING (CB &KEY (ERRORP T) OCTET-END)

MASK-OCTETS (CB MASK)

PEEK-OCTET (CB)

READ-OCTET (CB)

STATUS-CODE (CONDITION)

STATUS-MESSAGE (CONDITION)

SLOT-ACCESSOR

Public

Undocumented

CLIENT-CONNECTION-HEADERS (OBJECT)

SETFCLIENT-CONNECTION-HEADERS (NEW-VALUE OBJECT)

CLIENT-CONNECTION-REJECTED (OBJECT)

SETFCLIENT-CONNECTION-REJECTED (NEW-VALUE OBJECT)

CLIENT-HOST (OBJECT)

CLIENT-PORT (OBJECT)

CLIENT-QUERY-STRING (OBJECT)

SETFCLIENT-QUERY-STRING (NEW-VALUE OBJECT)

CLIENT-RESOURCE-NAME (OBJECT)

SETFCLIENT-RESOURCE-NAME (NEW-VALUE OBJECT)

CLIENT-WEBSOCKET-VERSION (OBJECT)

SETFCLIENT-WEBSOCKET-VERSION (NEW-VALUE OBJECT)

Private

%CLIENT-SERVER-HOOK (OBJECT)

Function to call to send a command to the network thread from other threads

CLIENT-CONNECTION-STATE (OBJECT)

State of connection: :connecting when initially created :headers while reading headers, :connected after server handshake sent :failed after an error has occurred and further input/output will be ignored :closing when close has been sent but not received from peer (input is still valid, but no more output will be sent)

SETFCLIENT-CONNECTION-STATE (NEW-VALUE OBJECT)

State of connection: :connecting when initially created :headers while reading headers, :connected after server handshake sent :failed after an error has occurred and further input/output will be ignored :closing when close has been sent but not received from peer (input is still valid, but no more output will be sent)

CLIENT-HANDLER-DATA (OBJECT)

Space for handler to store connection specific data.

SETFCLIENT-HANDLER-DATA (NEW-VALUE OBJECT)

Space for handler to store connection specific data.

CLIENT-READ-CLOSED (OBJECT)

Flag indicates read side of the connection is closed

SETFCLIENT-READ-CLOSED (NEW-VALUE OBJECT)

Flag indicates read side of the connection is closed

CLIENT-READ-QUEUE (OBJECT)

queue of decoded lines/frames

SETFCLIENT-READ-QUEUE (NEW-VALUE OBJECT)

queue of decoded lines/frames

CLIENT-READER (OBJECT)

Read handler for this queue/socket

SETFCLIENT-READER (NEW-VALUE OBJECT)

Read handler for this queue/socket

CLIENT-RESOURCE (OBJECT)

The resource object the client has requested-- Not the string, but the object.

SETFCLIENT-RESOURCE (NEW-VALUE OBJECT)

The resource object the client has requested-- Not the string, but the object.

CLIENT-SERVER (OBJECT)

The instance of WS:SERVER that owns this client.

CLIENT-SOCKET (OBJECT)

Bidirectional socket stream used for communicating with the client.

CLIENT-SOCKET-CLOSED (OBJECT)

Flag indicates connection is closed

SETFCLIENT-SOCKET-CLOSED (NEW-VALUE OBJECT)

Flag indicates connection is closed

CLIENT-WRITE-BUFFER (OBJECT)

Buffer being written currently, if last write couldn't send whole thing

SETFCLIENT-WRITE-BUFFER (NEW-VALUE OBJECT)

Buffer being written currently, if last write couldn't send whole thing

CLIENT-WRITE-CLOSED (OBJECT)

Flag indicates write side of the connection is closed

SETFCLIENT-WRITE-CLOSED (NEW-VALUE OBJECT)

Flag indicates write side of the connection is closed

CLIENT-WRITE-OFFSET (OBJECT)

Offset into write-buffer if write-buffer is set

SETFCLIENT-WRITE-OFFSET (NEW-VALUE OBJECT)

Offset into write-buffer if write-buffer is set

CLIENT-WRITE-QUEUE (OBJECT)

Queue of buffers (octet vectors) to write, or :close to kill connection :enable-read to reenable reader after being disabled for flow control (mailbox instead of queue since it tracks length).

RESOURCE-READ-QUEUE (RESOURCE)

The The concurrent mailbox used to pass messages between the server thread and resource thread.

SERVER-CLIENTS (OBJECT)

Hash of client objects to them selves (just used as a set for now).

Undocumented

%CLIENT-HOST (OBJECT)

BUFFER-END (OBJECT)

BUFFER-SIZE (OBJECT)

SETFBUFFER-SIZE (NEW-VALUE OBJECT)

BUFFER-START (OBJECT)

BUFFER-VECTOR (OBJECT)

CALLBACK (OBJECT)

SETFCALLBACK (NEW-VALUE OBJECT)

CHUNKS (OBJECT)

SETFCHUNKS (NEW-VALUE OBJECT)

END-OF-CHUNKS (OBJECT)

SETFEND-OF-CHUNKS (NEW-VALUE OBJECT)

ERROR-CALLBACK (OBJECT)

SETFERROR-CALLBACK (NEW-VALUE OBJECT)

FRAME-FIN (OBJECT)

SETFFRAME-FIN (NEW-VALUE OBJECT)

FRAME-LENGTH (OBJECT)

SETFFRAME-LENGTH (NEW-VALUE OBJECT)

FRAME-OPCODE (OBJECT)

SETFFRAME-OPCODE (NEW-VALUE OBJECT)

FRAME-OPCODE-OCTET (OBJECT)

SETFFRAME-OPCODE-OCTET (NEW-VALUE OBJECT)

MESSAGE-FUNCTION (OBJECT)

MESSAGE-OPCODE (OBJECT)

SETFMESSAGE-OPCODE (NEW-VALUE OBJECT)

PARTIAL-MESSAGE (OBJECT)

SETFPARTIAL-MESSAGE (NEW-VALUE OBJECT)

PARTIAL-VECTOR (OBJECT)

SETFPARTIAL-VECTOR (NEW-VALUE OBJECT)

PARTIAL-VECTOR-POS (OBJECT)

SETFPARTIAL-VECTOR-POS (NEW-VALUE OBJECT)

PREDICATE (OBJECT)

SETFPREDICATE (NEW-VALUE OBJECT)

SERVER-EVENT-BASE (OBJECT)

SETFSERVER-EVENT-BASE (NEW-VALUE OBJECT)

VARIABLE

Public

*DEBUG-ON-RESOURCE-ERRORS*

set to T to enter debugger on resource-handler errors, NIL to drop the connections and try to send a disconnect to handler.

*DEBUG-ON-SERVER-ERRORS*

set to T to enter debugger on server errors, NIL to just drop the connections.

*LOG-LEVEL*

set to NIL to disable log messages, T to enable

*MAX-CLIENTS*

Max number of simultaneous clients allowed (nil for no limit). Extra connections will get a HTTP 5xx response (without reading headers).

*MAX-READ-FRAME-SIZE*

Max size of frames allowed. Connection will be dropped if client sends a larger frame.

*PROTOCOL-76/00-SUPPORT*

set to NIL to disable draft-hixie-76/draft-ietf-00 support, true to enable.

Private

*MAX-HANDLER-READ-BACKLOG*

Max number of frames that can be queued before the reader will start throttling reads for clients using that queue (for now, just drops the connections...).

*MAX-HEADER-SIZE*

Default max header size in octets (not used yet?)

*MAX-READ-MESSAGE-SIZE*

Largest (incomplete) message allowed. Connection will be dropped if client sends a larger message. Malicious clients can cause lower amounts to be buffered indefinitely though, so be careful with large settings.

*MAX-WRITE-BACKLOG*

Max number of queued write frames before dropping a client.

*POLICY-FILE*

cross-domain policy file, used for the Flash WebSocket emulator.

*RESOURCES*

hash mapping resource name to (list of handler instance, origin validation function, ?)

Undocumented

*400-MESSAGE*

*403-MESSAGE*

*404-MESSAGE*

*CLOSE-FRAME*

*DRAFT-76/00-CLOSE-FRAME*

*POLICY-FILE-REQUEST*

*PROTOCOL-HEADER-PARSERS*

*SERVER-BUSY-MESSAGE*

*SUPPORTED-PROTOCOL-VERSIONS*

CLASS

Public

WS-RESOURCE

A server may have many resources, each associated with a particular resource path (like /echo or /chat). An single instance of a resource handles all requests on the server for that particular url, with the help of RUN-RESOURCE-LISTENER, RESOURCE-RECEIVED-FRAME, and RESOURCE-CLIENT-DISCONNECTED.

Private

CLIENT

Per-client data used by a WebSockets server.

FUNCALL-CUSTOM-MESSAGE

A type of so-called 'custom message' used to call a function on the main resource thread.

SERVER

A WebSockets server listens on a socket for connections and has a bunch of client instances that it controls.

Undocumented

BUFFER-CHUNK

BUFFERED-READER

CHUNK-BUFFER

CONDITION

Private

Undocumented

CLOSE-FROM-PEER

FAIL-THE-WEBSOCKETS-CONNECTION