Hubert Iwaniuk <neo...@kungfoo.pl> writes:

oh man, there was just missing "c/close", silly me ;)
now this function works perfectly:

<code>
(defn test-working
  []
  (let [response (c/GET "http://github.com/neotyk/http.async.client/";)]
    (c/await response)
    (println (c/string response))
    (c/close)))
</code

thanks for help, now back to my screen scraper :)

Br,
Rob

> Hi Rob,
>
> Please see following code:
> (ns twitter-stream
>   (:require [http.async.client :as c]
>             [org.danlarkin.json :as j]))
>
> (def u "...")
> (def p "...")
>
> (defn -main []
>   (let [resp (c/stream-seq :get 
> "http://stream.twitter.com/1/statuses/sample.json";
>                            :auth {:user "ahcclj" :password "ahcclj11"}
>                            :timeout -1)]
>     (doseq [twit-str (c/string resp)]
>       (try
>         (let [twit (j/decode-from-str twit-str)
>               u (get-in twit [:user :screen_name])
>               t (:text twit)]
>           (if (or (nil? u) (nil? t))
>             (println "Twit not decoded properly: " twit)
>             (println u "=>" t)))
>         (catch Exception e
>           (println "Failed to parse: " twit-str (.getMessage e))))))
>   
>   (c/close))
>
> You don't need to create new client.
>
> Now that I think of it it probably is a bug that one client is started by 
> default.
>
> HTH,
> Hubert.
>
> On Feb 9, 2011, at 4:21 PM, Rob Wolfe wrote:
>
>> 
>> I created another test function like this:
>> 
>> <code>
>> (defn test-http-with-close
>>  []
>>  (println "start")
>>  (binding [*client* (c/create-client)]
>>    (let [response (c/GET "http://github.com/neotyk/
>> http.async.client/")]
>>      (println "await")
>>      (c/await response)
>>      (println "string")
>>      (println (c/string response)))
>>    (println "close")
>>    (c/close *client*))
>>    (println "end"))
>> </code>
>> 
>> but it didn't help.
>> Are you using the same java version, clojure version and the same
>> versions of all libraries
>> and it does not hang?
>> There must be something.
>> 
>> Br,
>> Robert
>> 
>> 
>> On 9 Lut, 15:51, Hubert Iwaniuk <neo...@kungfoo.pl> wrote:
>>> Hi Rob,
>>> 
>>> You need to close the client once you are done with it.
>>> Please see "Managing http.async.client" of manual especially "Closing 
>>> http.async.client"http://neotyk.github.com/http.async.client/docs.html#sec-1_2_6_11
>>> 
>>> HTH,
>>> Hubert.
>>> 
>>> On Feb 9, 2011, at 3:29 PM, Rob Wolfe wrote:
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>> On 7 Lut, 19:30, Hubert Iwaniuk <neo...@kungfoo.pl> wrote:
>>>>> Hi All,
>>> 
>>>>> Just released v0.2.2 of HTTP Asynchronous Client.
>>> 
>>>> I have some problem using this library. Having such simple testing
>>>> program:
>>>> <code>
>>>> (ns test.http
>>>>  (:require [http.async.client :as c]))
>>> 
>>>> (defn test-http
>>>>  []
>>>>  (println "start")
>>>>  (let [response (c/GET "http://github.com/neotyk/
>>>> http.async.client/")]
>>>>    (println "await")
>>>>    (c/await response)
>>>>    (println "string")
>>>>    (println (c/string response))
>>>>    (println "end")))
>>> 
>>>> (defn -main
>>>>  []
>>>>  (println "start-app")
>>>>  (test-http)
>>>>  (println "end-app"))
>>>> </code>
>>> 
>>>> The output looks as follows:
>>> 
>>>> <output>
>>>> $ lein run
>>>> SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
>>>> SLF4J: Defaulting to no-operation (NOP) logger implementation
>>>> SLF4J: Seehttp://www.slf4j.org/codes.html#StaticLoggerBinderfor
>>>> further details.
>>>> start-app
>>>> start
>>>> await
>>>> string
>>>> <html>
>>>> <head><title>301 Moved Permanently</title></head>
>>>> <body bgcolor="white">
>>>> <center><h1>301 Moved Permanently</h1></center>
>>>> <hr><center>nginx/0.7.67</center>
>>>> </body>
>>>> </html>
>>>> end
>>>> end-app
>>> 
>>>> [...hangs for ever...]
>>> 
>>>> </output>
>>> 
>>>> But this program never ends, just hangs for ever.
>>>> I thought that it might be Windows issue where I first tried it,
>>>> but on Linux there is the same problem.
>>> 
>>>> Do you have any idea what I'm doing wrong or where might be the
>>>> problem?
>>> 
>>>> My environment looks as follows:
>>>> $ java -version
>>>> java version "1.6.0_17"
>>>> Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
>>>> Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)
>>>> $ lein version
>>>> Leiningen 1.4.2 on Java 1.6.0_17 Java HotSpot(TM) Client VM
>>>> $ ls lib
>>>> async-http-client-1.5.0.jar  clojure-1.2.0.jar  clojure-
>>>> contrib-1.2.0.jar  http.async.client-0.2.2.jar  netty-3.2.3.Final.jar
>>>> slf4j-api-1.6.1.jar
>>>> $ uname -a
>>>> WindowsNT ww011221 1 5 x86
>>> 
>>>> Br,
>>>> Rob
>>> 
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To post to this group, send email to clojure@googlegroups.com
>>>> Note that posts from new members are moderated - please be patient with 
>>>> your first post.
>>>> To unsubscribe from this group, send email to
>>>> clojure+unsubscr...@googlegroups.com
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/clojure?hl=en
>> 
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with your 
>> first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to