2018-12-02 02:09:38 -06:00
|
|
|
===============================================================================
|
2019-11-11 00:47:56 -06:00
|
|
|
FACILSERVIL : `Easy Server`
|
2018-12-02 02:09:38 -06:00
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
Sometimes, it's just annoying and time-draining to deal with all of the
|
2019-11-11 00:47:56 -06:00
|
|
|
intricacies of :usockets— facilservil abstracts away all of those bits.
|
2018-12-02 02:09:38 -06:00
|
|
|
|
|
|
|
|
2019-11-11 09:51:34 -06:00
|
|
|
————————————————————————————————————————
|
2018-12-02 02:09:38 -06:00
|
|
|
FEATURES
|
2019-11-11 09:51:34 -06:00
|
|
|
————————————————————————————————————————
|
2019-11-11 00:47:56 -06:00
|
|
|
* Multi-threaded
|
2018-12-02 02:09:38 -06:00
|
|
|
* Input-handling
|
2019-11-11 00:47:56 -06:00
|
|
|
* Logging system
|
2018-12-02 02:09:38 -06:00
|
|
|
* UTF-8
|
|
|
|
|
|
|
|
|
2019-11-11 09:51:34 -06:00
|
|
|
————————————————————————————————————————
|
2018-12-02 02:09:38 -06:00
|
|
|
DEMONSTRATION
|
2019-11-11 09:51:34 -06:00
|
|
|
————————————————————————————————————————
|
2018-12-02 02:09:38 -06:00
|
|
|
Load up Facilservil, then run this in your repl:
|
|
|
|
|
2019-11-11 00:47:56 -06:00
|
|
|
(facilservil:ex-server "localhost" 8888)
|
|
|
|
|
|
|
|
Now, connect your computer on port 8888.
|
|
|
|
This example server is a chat server, so it might be useful to connect a couple
|
|
|
|
of times, for demonstration's sake.
|
2018-12-02 02:09:38 -06:00
|
|
|
|
|
|
|
If you're on LiGNUx or BSD, you can use "telnet localhost 8888"
|
|
|
|
|
|
|
|
|
|
|
|
In reality, 'ex-server is just a small function for demonstration-- the
|
|
|
|
example server really looks like this:
|
|
|
|
|
2019-11-11 00:47:56 -06:00
|
|
|
(facilservil:server host port
|
|
|
|
#'ex-connect #'ex-disconnect #'ex-input #'ex-loop)
|
2018-12-02 02:09:38 -06:00
|
|
|
|
2019-11-11 00:47:56 -06:00
|
|
|
It runs #'ex-connect when you connect, #'ex-disconnect when you disconnect,
|
|
|
|
and #'ex-input-ex after you finish a command, and #'ex-loop after handling
|
|
|
|
everyone's input (or after timeout of waiting for input).
|
2018-12-02 02:09:38 -06:00
|
|
|
|
|
|
|
|
|
|
|
For a different kind of example (less interesting, since it takes no user
|
|
|
|
input), look at QOTDD (https://git.eunichx.us/qotdd).
|
|
|
|
|
|
|
|
For a more comprehensive guide to Facilservil, look to USAGE, coming right up.
|
|
|
|
|
|
|
|
|
2019-11-11 09:51:34 -06:00
|
|
|
————————————————————————————————————————
|
2018-12-02 02:09:38 -06:00
|
|
|
USAGE
|
2019-11-11 09:51:34 -06:00
|
|
|
————————————————————————————————————————
|
2019-11-11 00:47:56 -06:00
|
|
|
To use Facilservil, just use the `facilservil:server` function somewhere.
|
2018-12-02 02:09:38 -06:00
|
|
|
|
|
|
|
"host" and "port" are, obviously, the host-IP and port, respectively.
|
2019-11-11 00:47:56 -06:00
|
|
|
"on-connect" is the function that will be executed when a user connects.
|
|
|
|
"on-disconnect" is the function that will run when someone disconnects.
|
|
|
|
"on-input" is the function that will run when someone sends a command
|
|
|
|
"on-loop" is the function running when all input is complete/timeouts
|
2018-12-02 02:09:38 -06:00
|
|
|
|
|
|
|
|
|
|
|
Basically, you write the "connecting", "disconnecting", and "input-handler"
|
|
|
|
functions (maybe "halting"), and you've got a handy-dandy server.
|
|
|
|
|
|
|
|
These functions you write must accept the following arguments:
|
2019-11-11 00:47:56 -06:00
|
|
|
on-connect (connection connection-list)
|
|
|
|
on-disconnect (connection connection-list)
|
|
|
|
on-input (connection input-string connection-list)
|
|
|
|
on-loop (connection-list)
|
2018-12-02 02:09:38 -06:00
|
|
|
|
|
|
|
|
2019-11-11 00:47:56 -06:00
|
|
|
You can use #'send to send strings to a given connection.
|
2018-12-02 02:09:38 -06:00
|
|
|
|
2019-11-11 00:47:56 -06:00
|
|
|
Each connection has a built-in hashtable (for storing user-IDs, usernames,
|
|
|
|
whatever you need). You can store/set a variable with #'bury, and retrieve with
|
|
|
|
#'dig.
|
2018-12-02 02:18:47 -06:00
|
|
|
|
|
|
|
|
2019-11-11 09:51:34 -06:00
|
|
|
————————————————————————————————————————
|
2018-12-02 02:09:38 -06:00
|
|
|
BORING STUFF
|
2019-11-11 09:51:34 -06:00
|
|
|
————————————————————————————————————————
|
|
|
|
Based on Sergey's gist <sergey@polzunov.com>
|
2018-12-02 02:09:38 -06:00
|
|
|
Author is Jaidyn Ann <jadedctrl@teknik.io>
|
2019-11-11 09:51:34 -06:00
|
|
|
License is BSD 3-Clause “New”, see COPYING.txt
|
2019-11-11 00:47:56 -06:00
|
|
|
Sauce is at https://git.eunichx.us/facilservil.git
|