Home

Awesome

cl-websocket

A WebSocket-Server implemented in Common Lisp.

The server passes all tests of version v0.7.5/v0.10.9 of the autobahn testsuite except

Installation

This project is not available via quicklisp, but all its dependencies are. The easiest way to install is to clone cl-websocket into the local-projects directory of quicklisp and then to quickload it.

Clone:

cd ~/quicklisp/local-projects
git clone https://github.com/Frechmatz/cl-websocket.git

Load and install all dependencies:

(ql:quickload "cl-websocket")

Dependencies:

Example: Echo-Service

Load cl-websocket

(asdf:load-system "cl-websocket")

Define a handler class

(defclass echo-handler (clws.handler:connection-handler) ())

(defmethod clws.handler:on-open-connection ((handler echo-handler))
    (v:info :echo-handler "on-open-connection"))

(defmethod clws.handler:on-close-connection ((handler echo-handler) status-code reason)
    (v:info :echo-handler "on-close-connection"))

(defmethod clws.handler:on-text-message ((handler echo-handler) message)
    (v:info :echo-handler "on-text-message: ~a" message))
    (clws.handler:send-text-message handler message))

(defmethod clws.handler:on-binary-message ((handler echo-handler) message)
    (v:info :echo-handler "on-binary-message")
    (clws.handler:send-binary-message handler message))

Instantiate the server

(defparameter *server* (clws.server:make-websocketserver "localhost" 9001))

Register the handler class

(clws.server:register-resource-handler *server* "/echo" 'echo-handler '())

Start the server

(clws.server:start *server*)

WebSocket connections can now be established via ws://localhost:9001/echo

Stop the server

(clws.server:stop *server*)

API

Package clws.server

Package clws.handler

Logging

The server uses the Verbose framework for logging.

Set logging level (globally)

(setf (v:repl-level) :error)

Running the tests

The tests are using the lisp-unit framework. The system definition file is cl-websocket-test.asd.

Run all tests

(asdf:load-system "cl-websocket-test")
(in-package :cl-websocket-test)
(setf lisp-unit:*print-failures* t)
(use-debugger)
(run-tests)

Run a specific test

(asdf:load-system "cl-websocket-test")
(in-package :cl-websocket-test)
(setf lisp-unit:*print-failures* t)
(use-debugger)
(run-tests '(ping-test-1))

References

The Websocket Protocol: RFC 6455