paskvil

com.paskvil.uhttp-client.lisp

lisp/uhttp/com.paskvil.uhttp-client.lisp download

;;; -*- Lisp -*- mode

(in-package #:com.paskvil.uhttp)

(defun client-connect (addr &optional (port 80))
  "Connects to the socket run by the server at ADDR:PORT.
   Returns a stream for use with CLIENT-READ, CLIENT-SEND, and CLIENT-CLOSE."
  (usocket:socket-connect addr port))

(defun client-close (stream)
  "Closes the client socket STREAM returned by CLIENT-CONNECT, and the connection."
  (usocket:socket-close stream))

(defun client-read (stream)
  "Reads from a socket STREAM returned by CLIENT-CONNECT."
  (read (usocket:socket-stream stream)))

(defun client-send (string stream)
  "Write a STRING to socket STREAM returned by CLIENT-CONNECT."
  (print string (usocket:socket-stream stream))
  (force-output (usocket:socket-stream stream)))