trivial-ws
2018-01-31
Trivial WebSockets.
Upstream URL
Author
Fernando Borretti <eudoxiahp@gmail.com>
Maintainer
Fernando Borretti <eudoxiahp@gmail.com>
License
MIT
trivial-ws
Trivial WebSockets, built on top of Hunchensocket for the server and websocket-driver for the client.
Usage
Here's a simple echo server:
(defvar *server* (trivial-ws:make-server :on-connect #'(lambda (server) (format t "Connected~%")) :on-disconnect #'(lambda (server) (format t "Disconnected~%")) :on-message #'(lambda (server message) (format t "Received: ~A~%" message) (trivial-ws:send (first (trivial-ws:clients server)) message))))
Then start it:
(defvar *handler* (trivial-ws:start *server* 4040))
Then go to http://www.websocket.org/echo.html and change the server to
ws://localhost:4040/
and try it out.
You can stop it with (trivial-ws:stop *handler*)
.
Inside the callbacks you can use two functions: (trivial-ws:clients server)
will return the list of connected clients, and (trivial-ws:send client "string")
will send a message to a selected client.
License
Copyright (c) 2016 Fernando Borretti
Licensed under the MIT License.