Mark ENOLINK and EMULTIHOP as optional
[iolib.git] / examples / ex1-client.lisp
blob424874131ed0c5c1c070426656df073c155080a6
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
16 ;;;; examples.
18 ;; ex-0b
19 (defun run-ex1-client (&key (host *host*) (port *port*))
20 ;; ex-0e
22 ;; ex-1b
23 ;; Create a internet TCP socket under IPV4
24 (let ((socket
25 (make-socket
26 :connect :active
27 :address-family :internet
28 :type :stream
29 :external-format '(:utf-8 :eol-style :crlf)
30 :ipv6 nil)))
31 ;; ex-1e
33 ;; ex-2b
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))
39 ;; ex-2e
41 ;; ex-3b
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)))
45 (format t "~A" line))
46 ;; ex-3e
48 ;; ex-4b
49 ;; all done
50 (close socket)
51 t))
52 ;; ex-4e