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 similar to ex2-client.lisp, except we've added in
7 ;;;; catching of various conditions which may be signaled during the
8 ;;;; network communication.
11 (defun run-ex3-client-helper (host port
)
13 ;; Create a internet TCP socket under IPV4
15 (socket :connect
:active
16 :address-family
:internet
18 :external-format
'(:utf-8
:eol-style
:crlf
)
21 ;; do a blocking connect to the daytime server on the port.
22 (connect socket
(lookup-hostname host
) :port port
:wait t
)
23 (format t
"Connected to server ~A:~A from my local connection at ~A:~A!~%"
24 (remote-name socket
) (remote-port socket
)
25 (local-name socket
) (local-port socket
))
28 ;; read the one line of information I need from the daytime
29 ;; server. I can use read-line here because this is a TCP
30 ;; socket. It will block until the whole line is read.
31 (let ((line (read-line socket
)))
35 ;; However, let's notice the signaled condition if the server
36 ;; went away prematurely...
38 (format t
"Got end-of-file. Server closed connection!")))))
42 ;; The main entry point into ex3-client
43 (defun run-ex3-client (&key
(host *host
*) (port *port
*))
46 (run-ex3-client-helper host port
)
48 ;; handle a commonly signaled error...
49 (socket-connection-refused-error ()
50 (format t
"Connection refused to ~A:~A. Maybe the server isn't running?~%"
51 (lookup-hostname host
) port
))))