数日間試しましたが、ここで少し混乱しています。clojure http-kit を使用してキープアライブ get リクエストを作成しています。
(ns weibo-collector.weibo
(:require [org.httpkit.client :as http]
[clojure.java.io :as io]))
(def sub-url "http://c.api.weibo.com/datapush/status?subid=10542")
(defn spit-to-file [content]
(spit "sample.data" content :append true))
@(http/get sub-url {:as :stream :keepalive 3000000}
(fn [{:keys [status headers body error opts]}]
(spit-to-file body)
))
ターゲット サーバーへの永続的な接続を確立したことは確かですが、sample.data ファイルには何も書き込まれていません。ストリームとテキストとして試しました。
また、プログラムが永続的な接続を作成するRubyバージョンも試しましたが、まだ何も書かれていません。
通常、ターゲットはWebhookを使用してサーバーに新しいデータが来ることを通知しますが、永続的な接続からデータを取得するにはどうすればよいですか?
- -編集 - -
require 'awesome_print'
url = "http://c.api.weibo.com/datapush/status?subid=10542"
require "httpclient"
c = HTTPClient.new
conn = c.get_async(url)
Thread.new do
res = conn.pop
while true
text = ""
while ch = res.content.read(1)
text = text+ch
break if text.end_with? "\r\n"
end
ap text
end
end
while true
end
上記は ruby を使用した実際の例で、スレッドを使用して接続からデータを読み取ります。だから私はclojureからデータを取得するために何かを見逃す必要があります