Access to sockets is not part of the ANSI CL standard, so the details
Jorge Tavares <j...
> Hello all,
> I wanted to try to make a simple client server aplication with
> TCP sockets but I was unable to find information on the subject.
> The books I have don't talk about it and I have tried to find some
> web pages but didn't get anything. I've also tried to look in
> deja news but the serach results didn't give me a clear picture
> of the subject. I was able to realise that there must be something
> like open-tcp-stream and then work like a normal stream but I
> think there is more to the subject. If somebody would be kind
> enough to point me in some direction I would be apreciate.
> Thanks !
of this will vary between implementations, although the general
principle (that you describe above) will be similar. Erik has already
posted hints for ACL, here are some more for other systems:
a) Get cl-http, which would include implementation specific code for
listening and opening on sockets for nearly all implementations
b) For CMUCL, this is the skeleton of code that is needed to listen on
a socket and spawn functions that handle connections (this uses
multi-processing, so will only work in this way on iA32):
(defun ip-address-string (address)
(format nil "~D.~D.~D.~D"
(ldb (byte 8 24) address)
(ldb (byte 8 16) address)
(ldb (byte 8 8) address)
(ldb (byte 8 0) address)))
(defun http-listener (port server)
(let ((fd (ext:create-inet-listener port)))
(unless fd (error "Cannot bind port ~D." port))
(setf (process-name *current-process*)
"HTTP connection listener on port ~D with server ~A"
(format t "~&;;; Started lisp connection listener on ~
port ~d for server ~A~%" port server)
;; Wait for new connection
(process-wait-until-fd-usable fd :input)
(format t "~&;;; At ~D Got Connection...~%"
(multiple-value-bind (new-fd remote-host)
(format t "~&;;; At ~D Have Connection...~%"
(let* ((host-entry (ext:lookup-host-entry remote-host))
(stream (sys:make-fd-stream new-fd :input t :output t))
(connection (make-instance 'simple-connection
(format t "~&;;; At ~D Established Connection...~%"
(serve-connection server connection))
:name (format nil "HTTP connection from ~A"
(when fd (unix:unix-close fd)))))
(defun start-http-listener (port server)
(make-process #'(lambda () (http-listener port server))))
(defun initialize-clash (&optional (idle-process mp::*initial-process*))
(setf mp::*idle-process* idle-process))
Pierre Mai <p...@acm.org> PGP and GPG keys at your nearest Keyserver
"One smaller motivation which, in part, stems from altruism is Microsoft-
bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]