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.
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.
16 (socket :connect
:active
17 :address-family
:internet
19 :external-format
'(:utf-8
:eol-style
:crlf
)
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
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
)))