Open a socket-stream connection to server host, perform a series of operations on the connection, and then close the connection.
Arguments and values
|var||A variable symbol|
|host||A 32-bit internet address or a string specifying the remote host|
|port||An integer or a string specifying the service port|
|declaration||A declare expression (not evaluated)|
|forms|| An implicit |
This macro ensures that the opened connection is closed when control leaves the body of the macro.
A host string can be either a host name or a “dotted” IP address,
String values available for specifying port are found in the operating
system's services file and labeled as being
tcp services. On Unix
systems, the services file is
Open a socket connection to the GBBopen Project web server:
> (with-open-connection (connection "GBBopen.org" 80) (flet ((write-crlf (stream) ;; HTTP requires CR/LF line termination: (write-char #\return stream) (write-char #\linefeed stream))) (format connection "GET / HTTP/1.1") (write-crlf connection) (format connection "Host: ~a:~a" host port) (write-crlf connection) (write-crlf connection) (force-output connection) (let ((line (read-line connection))) (format t "~&;; Received: ~a~%" line)))) ;; Received: HTTP/1.1 200 OK >
The GBBopen Project