edgar-rft wrote:I'm no SBCL socket specialist either, but the SBCL sockets example, please? thread from comp.lang.lisp gives some code examples.
(defun start-socket-server (callback &key (qlen 6) (port 5432))
"Start a server socket listening process running in it's own thread.
For each request received, <callback> is invoked in a separate thread."
(let ((socket (make-instance 'inet-socket
;; Seems to fix issue with sockets stuck in CLOSED state.
(setf (sockopt-reuse-address socket) t)
(socket-bind socket #(0 0 0 0) port)
(socket-listen socket qlen) ;; Number of request to queue.
(format t "Socket is configured. Entering listening loop.~%")
(when (not *server-mode*) (return))
(write-line "Listening for request.")
(let ((client-socket (socket-accept socket)))
(funcall callback client-socket)))
(write-line "Closing server socket.")
(defun run-webserver (&key (port 2540))
(setf *server-mode* t)
(let ((server-thread (start-socket-server
(join-thread server-thread :default 'DONE))))
pjstirling wrote:IMO land of lisp should just have used hunchentoot for its web server chapter. It's portable and a fully functional, unlike the toy that it presents
Users browsing this forum: No registered users and 1 guest