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 ;;;; The entry call to this example is: (run-ex1-client) It can take
7 ;;;; two keyword arguements of :host STRING and :port INTEGER.
9 ;;;; This example implements a very simple IPV4 TCP blocking i/o
10 ;;;; client which talks to a date server. After connecting to the date
11 ;;;; server, a single line is sent from the server to the cilent and
12 ;;;; then the client disconnects.
14 ;;;; We don't handle many errors and this code is written from a
15 ;;;; C-style perspective that we will avoid where possible in future
19 (defun run-ex1-client (&key
(host *host
*) (port *port
*))
23 ;; Create a internet TCP socket under IPV4
27 :address-family
:internet
29 :external-format
'(:utf-8
:eol-style
:crlf
)
34 ;; do a blocking connect to the daytime server on the port.
35 (connect socket
(lookup-hostname host
) :port port
:wait t
)
36 (format t
"Connected to server ~A:~A via my local connection at ~A:~A!~%"
37 (remote-host socket
) (remote-port socket
)
38 (local-host socket
) (local-port socket
))
42 ;; read the one line of information I need from the daytime
43 ;; server. I can use read-line here because this is a TCP socket.
44 (let ((line (read-line socket
)))