Function
comm
open-tcp-stream hostname service &key direction element-type buffered => stream-object
An integer or string.
A string or a fixnum.
One of:input,:output or:io.
One ofbase-char,unsigned-byte orsigned-byte.
A boolean.
A socket stream.
open-tcp-stream function attempts to connect to a socket on another machine and returns stream-object for the connection if successful. The server machine to connect to is given by hostname, which can be one of the following:"www.nowhere.com""204.71.177.75"#xCC47B14BSERVICES and is stored in theWindows directory., and on Windows NT it is the file %SystemRoot%\system32\drivers\etc\SERVICES
:io. The element type of the connection is given by element-type, and isbase-char by default. nil, failure to connect returnsnil, otherwise an error is signaled.
(with-open-stream (http (comm:open-tcp-stream
"webhost" 80))
(format http "GET / HTTP/1.0~C~C~C~C"
(code-char 13) (code-char 10)
(code-char 13) (code-char 10))
(force-output http)
(write-string "Waiting to reply...")
(loop for ch = (read-char-no-hang http nil :eof)
until ch
do (write-char #\.)
(sleep 0.25)
finally (unless (eq ch :eof)
(unread-char ch http)))
(terpri)
(loop for line = (read-line http nil nil)
while line
do (write-line line)))
start-up-server