Re: socket streams

"Eric Blood" <[email protected]> Tue, 13 May 2003 22:48:28 -0000
Newsgroups gmane.lisp.corman
Message-ID <[email protected]>
One more follow-up...  The test I had was flawed, and here it is with
the fixes.  

(let ((s (make-client-socket :host "www.double.co.nz" :port 80)))
  (let ((stream (make-socket-stream s)))
    (write-line "GET / HTTP/1.0" stream)
    (write-line "" stream)
    (force-output stream)
    (loop as line = (read-line stream nil nil)
          until (null line)
          do (format t "~A~%" line)))
  (close-socket s))

Here is something I think is cool--a network read-eval-print loop.
The only problems are it doesn't handle backspaces, and the debugger
doesn't work very well.  However, for the number of lines it takes to
do this, it still amazes me.  After the thread is created, just telnet
to port 8000.

(require 'sockets)
(use-package 'sockets)
(use-package 'threads)
(start-sockets)

(defun repl-server (&optional (port 8000))
  (with-server-socket (socket :host "0.0.0.0" :port port)
    (start-socket-server (socket remote-socket)
     (let* ((stream (make-socket-stream remote-socket))
            (*standard-output* stream)
            (*standard-input* stream)
            (*error-output* stream)
            (*trace-output* stream)
            (*debug-io* stream)
            (*query-io* stream))
       (top-level)))))

(create-thread #'repl-server)

-- 
eblood


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Rent DVDs from home.
Over 14,500 titles. Free Shipping
& No Late Fees. Try Netflix for FREE!
http://us.click.yahoo.com/BVVfoB/hP.FAA/uetFAA/SyjtlB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/