Clojure如何从套接字读取数据

时间:2019-11-02 01:59:03

标签: sockets clojure

我已经向回显服务器发出了tcp请求,并希望从服务器获取回显消息,但是java.io/copy被阻止,直到服务器关闭客户端连接,我才能得到该消息吗?

(defn send-request
  "Sends an HTTP GET request to the specified host, port, and path"
  [host port path]
  (with-open [sock (Socket. host port)
              writer (io/writer sock)
              reader (io/reader sock)
              response (StringWriter.)]
    (.append writer (str "jeff-test"))
    (.flush writer)
    ; block here till server close the connection
    (io/copy reader response)
    (println (slurp reader))
    (println "end   read\n")))
    (str response)
    (println response)))

0 个答案:

没有答案