The trivial-ws Reference Manual

This is the trivial-ws Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Feb 26 18:09:27 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 trivial-ws

Trivial WebSockets.

Maintainer

Fernando Borretti <>

Author

Fernando Borretti <>

Home Page

https://github.com/ceramic/trivial-ws

Source Control

(GIT git@github.com:ceramic/trivial-ws.git)

Bug Tracker

https://github.com/ceramic/trivial-ws/issues

License

MIT

Long Description

# trivial-ws

Trivial WebSockets, built on top of [Hunchensocket][hs] for the server and [websocket-driver][driver] for the client.

# Usage

Here’s a simple echo server:

~~~lisp
(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:

~~~lisp
(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.

[hs]: https://github.com/capitaomorte/hunchensocket
[driver]: https://github.com/fukamachi/websocket-driver

Version

0.1

Dependency

hunchensocket (system).

Source

trivial-ws.asd.

Child Component

src (module).


3 Modules

Modules are listed depth-first from the system components tree.


3.1 trivial-ws/src

Source

trivial-ws.asd.

Parent Component

trivial-ws (system).

Child Component

server.lisp (file).


4 Files

Files are sorted by type and then listed depth-first from the systems components trees.


4.1 Lisp


4.1.1 trivial-ws/trivial-ws.asd

Source

trivial-ws.asd.

Parent Component

trivial-ws (system).

ASDF Systems

trivial-ws.


4.1.2 trivial-ws/src/server.lisp

Source

trivial-ws.asd.

Parent Component

src (module).

Packages

trivial-ws.

Public Interface
Internals

5 Packages

Packages are listed by definition order.


5.1 trivial-ws

Trivial WebSockets.

Source

server.lisp.

Use List

common-lisp.

Public Interface
Internals

6 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


6.1 Public Interface


6.1.1 Special variables

Special Variable: +default-address+
Package

trivial-ws.

Source

server.lisp.

Special Variable: +default-timeout+
Package

trivial-ws.

Source

server.lisp.


6.1.2 Ordinary functions

Function: clients (server)

Return a list of server clients.

Package

trivial-ws.

Source

server.lisp.

Function: make-server (&key on-connect on-disconnect on-message)

Create a server given the three callback functions.

Package

trivial-ws.

Source

server.lisp.

Function: send (client string)

Send a string of text to the client.

Package

trivial-ws.

Source

server.lisp.

Function: start (server port &key address timeout)

Start the server. Returns a handler object.

Package

trivial-ws.

Source

server.lisp.

Function: stop (handler)

Stops a server handler.

Package

trivial-ws.

Source

server.lisp.


6.1.3 Standalone methods

Method: client-connected ((server server) client)
Package

hunchensocket.

Source

server.lisp.

Method: client-disconnected ((server server) client)
Package

hunchensocket.

Source

server.lisp.

Method: text-message-received ((server server) client message)
Package

hunchensocket.

Source

server.lisp.


6.1.4 Classes

Class: server
Package

trivial-ws.

Source

server.lisp.

Direct superclasses

websocket-resource.

Direct methods
Direct Default Initargs
InitargValue
:client-class(quote client)
Direct slots
Slot: on-connect

The function that is called when a client connects.

Type

function

Initform

(function (lambda (trivial-ws:server) (declare (ignore trivial-ws:server)) nil))

Initargs

:on-connect

Readers

on-connect.

Writers

This slot is read-only.

Slot: on-disconnect

The function that is called when a client disconnects.

Type

function

Initform

(function (lambda (trivial-ws:server) (declare (ignore trivial-ws:server)) nil))

Initargs

:on-disconnect

Readers

on-disconnect.

Writers

This slot is read-only.

Slot: on-message

The function that’s called when a client sends a message.

Type

function

Initform

(function (lambda (trivial-ws:server trivial-ws::message) (declare (ignore trivial-ws:server trivial-ws::message)) nil))

Initargs

:on-message

Readers

on-message.

Writers

This slot is read-only.


6.2 Internals


6.2.1 Generic functions

Generic Reader: name (object)
Package

trivial-ws.

Methods
Reader Method: name ((client client))

automatically generated reader method

Source

server.lisp.

Target Slot

name.

Generic Reader: on-connect (object)
Package

trivial-ws.

Methods
Reader Method: on-connect ((server server))

The function that is called when a client connects.

Source

server.lisp.

Target Slot

on-connect.

Generic Reader: on-disconnect (object)
Package

trivial-ws.

Methods
Reader Method: on-disconnect ((server server))

The function that is called when a client disconnects.

Source

server.lisp.

Target Slot

on-disconnect.

Generic Reader: on-message (object)
Package

trivial-ws.

Methods
Reader Method: on-message ((server server))

The function that’s called when a client sends a message.

Source

server.lisp.

Target Slot

on-message.


6.2.2 Classes

Class: client
Package

trivial-ws.

Source

server.lisp.

Direct superclasses

websocket-client.

Direct methods

name.

Direct slots
Slot: name
Initargs

:user-agent

Readers

name.

Writers

This slot is read-only.


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   C   F   G   M   N   O   S   T  
Index Entry  Section

C
client-connected: Public standalone methods
client-disconnected: Public standalone methods
clients: Public ordinary functions

F
Function, clients: Public ordinary functions
Function, make-server: Public ordinary functions
Function, send: Public ordinary functions
Function, start: Public ordinary functions
Function, stop: Public ordinary functions

G
Generic Function, name: Private generic functions
Generic Function, on-connect: Private generic functions
Generic Function, on-disconnect: Private generic functions
Generic Function, on-message: Private generic functions

M
make-server: Public ordinary functions
Method, client-connected: Public standalone methods
Method, client-disconnected: Public standalone methods
Method, name: Private generic functions
Method, on-connect: Private generic functions
Method, on-disconnect: Private generic functions
Method, on-message: Private generic functions
Method, text-message-received: Public standalone methods

N
name: Private generic functions
name: Private generic functions

O
on-connect: Private generic functions
on-connect: Private generic functions
on-disconnect: Private generic functions
on-disconnect: Private generic functions
on-message: Private generic functions
on-message: Private generic functions

S
send: Public ordinary functions
start: Public ordinary functions
stop: Public ordinary functions

T
text-message-received: Public standalone methods