Peter Hertmuller <phertmuller <at> gmail.com> writes:
> I don't know how to change the String to an instruction understable by
> the server. This means, how the server could translate from the String
Peter,
You might want to look at cl-store: http://common-lisp.net/project/cl-store/.
It is a library for serializing Common Lisp objects, storing them somewhere and
restoring them. The examples in the manual use a file as the destination place,
but a stream works just fine.
The thing I was building was a remote-eval server. You manually start up the
remote-eval server on the server with something like:
(start-remote-eval-server :port *default-remote-eval-server-port*)
This starts a socket server listening for remote-eval requests.
Then the client calls the remote-eval server with something like:
(remote-eval '(car ((a b c) d e f)) "server-host-name"
*default-remote-eval-server-port*)
remote-eval opens a stream to the server, serializes the form using cl-store,
and writes it to the stream and reads (in a blocking way) the result from the
stream.
The server gets the form, spawns off a worker thread & socket, reads from the
socket de-serializes the form, evaluates it with EVAL, serializes the result,
writes it back to the stream and then ends.
remote-eval then gets the serialized result from the read, de-serializes it and
returns it as the result of remote-eval, in this example
(A B C)
Some care was taken to allow the remote form to return multiple values and to
signal an error, in which case the condition is serialized and sent back as the
result, which is then either returned directly or re-signalled in the client
(depending on a parameter to the remote-eval call).
The advantage to something this is that it is a completely flexible mechanism
for doing what you outlined and can be reused in lots of different contexts.
You can develop your application protocol with functions or methods, then use a
remote evaluation strategy similar to what I outlined to just execute your
functions. You can then use the same remote-eval mechanism for anything else.
Because cl-store handles the serialization / de-serialization for you
automatically, your stream reads & writes involve serialized Common Lisp
objects, instead of string representations.
cl-store is pretty remarkable. About the only things that it can't serialize
are implementation dependent representations of things like closures,
functions, threads, open streams, what not. It handles all "normal" Common Lisp
data just fine.
I can't publish the code, because it's work I've done for my employer, but if
you want to discuss questions and how I solved them, feel free to ask here, or
privately in email. I'd be willing to share code snippets.
Glenn
|