Attempts to connect to a socket on another machine and returns a stream object for the connection.
An integer or string.
A string or a fixnum.
or a subtype of
A positive number, or
A socket stream.
function attempts to connect to a socket on another machine and returns
for the connection if successful. The server machine to connect to is given by
, which can be one of the following:
A string naming the host, for example
A string providing the IP address, for example
An integer IP address in network order, for example
The name of the service to provide is given by
is a string, the location of the file specifying the names of the services available varies, but typically on Windows 95 it is called
and is stored in the
directory., and on Windows NT it is the file
can also be a fixnum representing the port number of the desired connection.
The direction of the connection is given by
. Its default value is
. The element type of the connection is determined from
, and is
, failure to connect returns
, otherwise an error is signaled.
specifies the read-timeout of the stream. If it is
(the default), the stream does not timeout during reads, and these may hang. See socket-stream for more details.
The following example opens an HTTP connection to a given host, and retrieves the root page:
(with-open-stream (http (comm:open-tcp-stream
(format http "GET / HTTP/1.0~C~C~C~C"
(code-char 13) (code-char 10)
(code-char 13) (code-char 10))
(write-string "Waiting to reply...")
(loop for ch = (read-char-no-hang http nil :eof)
do (write-char #\.)
finally (unless (eq ch :eof)
(unread-char ch http)))
(loop for line = (read-line http nil nil)
do (write-line line)))
LispWorks Reference Manual - 25 Jul 2003