Remove debug declarations
[iolib.git] / examples / ex2-client.lisp
blob53c04243454abfcee76f4506726b7c14cd78ae0d
1 (in-package :iolib.examples)
3 ;;;; This file was originally written by Peter Keller (psilord@cs.wisc.edu)
4 ;;;; and this code is released under the same license as IOLib.
6 ;;;; This example is almost the same as ex1-client.lisp, except we move it
7 ;;;; closer to a Common Lisp style.
9 ;; ex-0b
10 (defun run-ex2-client (&key (host *host*) (port *port*))
12 ;; We introduce with-open-socket here as a means to easily wrap
13 ;; usually synchronous and blocking communication with a form that
14 ;; ensures the socket is closed no matter how we exit it.
15 (with-open-socket
16 (socket :connect :active
17 :address-family :internet
18 :type :stream
19 :external-format '(:utf-8 :eol-style :crlf)
20 :ipv6 nil)
22 ;; Do a blocking connect to the daytime server on the port. We
23 ;; also introduce lookup-hostname, which converts a hostname to an
24 ;; 4 values, but in our case we only want the first, which is an
25 ;; address.
26 (connect socket (lookup-hostname host) :port port :wait t)
27 (format t "Connected to server ~A:~A from my local connection at ~A:~A!~%"
28 (remote-name socket) (remote-port socket)
29 (local-name socket) (local-port socket))
31 ;; read the one line of information I need from the daytime
32 ;; server. I can use read-line here because this is a TCP
33 ;; socket. It will block until the whole line is read.
34 (let ((line (read-line socket)))
35 (format t "~A" line)
36 t)))
37 ;; ex-0e