[Openmcl-devel] Open socket as file stream example for CCL?
R. Matthew Emerson
rme at clozure.com
Wed Jun 23 02:47:51 UTC 2010
On Jun 22, 2010, at 4:36 PM, Harald Striepe wrote:
> Does anybody have a working example to open a socket as a file stream and read from it?
> I have spent several hours going in circles without meaningful results, and it is likely that somebody has the ten lines of code required working.
You might like to look at ccl:contrib;perryman;finger.lisp.
Here's a shorter example distilled from that file:
(defun sample-server (port)
(with-open-socket (s :connect :passive :local-port port :reuse-address t)
(let ((stream (accept-connection s)))
(process-run-function "request handler" #'handle-request stream)))))
(defun handle-request (stream)
(format stream "hello there~%")
(defun sample-client (port)
(with-open-socket (s :remote-host "127.0.0.1" :remote-port port)
(defun start-sample-server (port)
(process-run-function "sample server" #'sample-server port))
To run it, do something like:
? (start-sample-server 8888)
#<PROCESS sample server(75) [Reset] #x302000A10A8D>
? (sample-client 8888)
More information about the Openmcl-devel