I am using HTTP-KIT for write a simple server and client HTTP. And now I want to send some data encoded using gloss.
My gloss code is something like this:
(gcore/defcodec sized-string (gcore/finite-frame :uint16-be
(gcore/string :utf-8)))
(gcore/defcodec ordered-map-codec
(gcore/ordered-map :msg sized-string
:type sized-string))
This code works well:
(def data {:msg "Hello World", :type "alert"})
(def encoded
(gio/encode ordered-map-codec data))
(gio/decode ordered-map-codec encoded)
In my server/client HTTP code, I have:
For the server:
(defonce server (atom nil))
(defn handler [request]
(println (gio/decode ordered-map-codec (get request :body ))))
(defn -main
[]
(reset! server (run-server handler {:port 8080})))
And for the client:
(def options {:timeout 200
:body (gio/encode ordered-map-codec data)})
(http/post "http://localhost:8080" options
(fn [{:keys [status headers body error]}]
(if error
(println "Failed, exception is " error)
(println "Async HTTP GET: " status))))
Then when I try use the client to send some data
:
Sat Apr 18 11:24:24 BRT 2015 [worker-3] ERROR - GET /
java.lang.Exception: Insufficient bytes to decode frame.
at gloss.io$decode.invoke(io.clj:85)
at gloss.io$decode.invoke(io.clj:79)
at tapahtuma_server.server$handler.invoke(server.clj:35)
at org.httpkit.server.HttpHandler.run(RingHandler.java:91)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Async HTTP GET: 500
Thanks for any help here