;;; ;;; examples.cl ;;; Last Modified: 13:25:28 on Fri 22-Sep-2000 ;;; ;;; Example functions and tests of Ira's sockets code. ;;; ;;; 31-Dec-1996 I. Kalet wrote finger client ;;; (in-package :common-lisp-user) (unless (fboundp 'so::TCP-SERVER) (load "sockets")) (use-package :socket) ;;;------------------------------------------------------------- ;;; a client function for the finger protocol ;;;------------------------------------------------------------- (defun finger (host stuff &optional port) "finger host stuff &optional port connects to the FINGER service or or the service specified by PORT, on HOST, a STRING specifying a domain name or IP address in dot form, sending STUFF, a STRING containing a username to search for. Prints to the terminal output whatever the remote service returns, a buffer at a time." (let ((desc (so:tcp-connect host (or port "finger"))) (buffer (make-string 80))) (so:tcp-write desc (format nil "~A~%" stuff) (1+ (length stuff))) (loop (if (> (so:tcp-read desc buffer 80) 0) (format t "~A" buffer) (return nil))) (finish-output) ; is this necessary? (so:tcp-close desc))) ;;;------------------------------------------------------------- ;;; A Hello-World server - ;;; Works with a variation of the FINGER client. ;;;------------------------------------------------------------- (defun hello-server (port) "hello-server port waits for connection requests on PORT, accepts a STRING, presumably the name of the client user, and responds, with the string Hello , where is the string the client sent." (so:tcp-server port 5 #'(lambda (desc) (let* ((buffer (make-string 80)) (length (so:tcp-read desc buffer 80))) (so:tcp-write desc (format nil "Hello, ~A~%" buffer) (+ length 8)))))) ;;;============================================================= ;;; End.