   (try
     (.readLine in)
     (catch java.net.SocketTimeoutException e
-      nil)))
+      :timeout)))
 
 (defn connect
   ([] (connect *host* *port*))

    (.write out (.getBytes (str command "\n")))
    (.flush out)))

(defn expect
  ([socket pattern] (expect socket pattern (or *timeout* 0)))
  ([socket pattern timeout]
     (.setSoTimeout (:socket socket) timeout)
     (let [in (:in socket)]
       (loop [received []]
         (let [line (socket-read-line in)]
                                        ; (println "RECEIVED:" line) ;; verbose mode
           (if (nil? line)
             (join "\n" received)
             (if (re-find pattern line)
               true
               (recur (conj received line)))))))))

(defmethod assert-expr 'received? [msg form]
  (let [socket (nth form 1)

               (.setSoTimeout 1000))]
       {:socket s
        :in (BufferedReader. (InputStreamReader. (.getInputStream s)))
        :out (.getOutputStream s)
        :received (atom [])})))

(defmacro with-connection [s & body]
  `(let [~s (connect)]
