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
Inside the callbacks you can use two functions:
will return the list of connected clients, and
(trivial-ws:send client "string") will send a message to a selected client.
Copyright (c) 2016 Fernando Borretti
Licensed under the MIT License.