This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Socket programming


| Date: Tue, 30 Sep 1997 21:34:27 +0100
| From: Sascha Ziemann <szi@aibon.ping.de>
| 
| Hi,
| 
| the Perl book contains a example program that shows how to write a
| simple daemon. Does such an example exist for Guile too?
| 

Here's a complicated way to write a simple daemon.  talk to it by
telnetting to port 20004:

(let ((port (socket AF_INET SOCK_STREAM 0))
      (inet-port 20004))          ; Some unused port.
  (bind port AF_INET INADDR_ANY inet-port)
  (listen port 10)                ; Queue up to 10 requests.
  (let loop ()
    (let ((p (accept port)))
      (display "Incoming connection from ")
      (display (inet-ntoa (sockaddr:addr (cdr p))))
      (display " port ")
      (display (sockaddr:port (cdr p)))
      (newline)
      (let next-line ()
          (let ((line (read-line (car p))))
             (cond ((eof-object? line)
                    (display "EOF\n"))
                   (else
                    (display line)
                    (newline)
		    (display "you sent:\n" (car p))
		    (display line (car p))
		    (newline (car p))
                    (next-line)))))
      (close-port (car p))
      (loop))))

Some wrapper functions would probably be useful, or maybe something
from the scsh module.