This document covers some parts of Land of Lisp that specifically require CLISP.
CLISP has a neat little socket library… Here is how you can create a server, allow it to accept connections, and connect to it:
Creating a socket:
(defparameter my-socket (socket-server 4321))
The function socket-server
creates a socket bound to the port
passed in as its first parameter.
Then, when we want to accept something on that port, we call the
blocking ”socket-accept
”:
(defparameter my-stream (socket-accept my-socket))
Then, we can connect with the following code from a second instance of CLISP:
(defparameter my-stream (socket-connect 4321 "127.0.0.1"))
This will create a bi-directional stream on both CLISP instances… That means we can both read and write to either side.
Now, you can read
, format
, print
, princ
, or any number of
commands that work with streams on either side.
To close a socket stream, you can run the following on the client:
(close my-stream)
And on the server, we can run:
(socket-server-close my-socket)