Skip to content

Instantly share code, notes, and snippets.

@shlomiv
Last active December 15, 2015 17:59
Show Gist options
  • Save shlomiv/5300921 to your computer and use it in GitHub Desktop.
Save shlomiv/5300921 to your computer and use it in GitHub Desktop.
(def chopped-codec
(finite-frame
(prefix :int32)
[:uuid :int32 (repeated (finite-frame (prefix :int16) (string :utf8)) :prefix :none)]))
(def response-chopped-codec
(finite-frame
(prefix :int32)
[:uuid :int32 (repeated :int64 :prefix :none)]))
(defn verbose-test []
(binding [*out* *out*]
(defn handler [ch client-info]
"handler for incoming tcp messages"
(register-extra-handlers ch client-info)
(siphon (map* (fn [x] [:uuid 1000 [1 4]]) ch) ch))
(def server (start-tcp-server
handler
{:port 9997 :encoder response-chopped-codec :decoder chopped-codec}))
(def client (tcp-client
{:host "127.0.0.1" :port 9997 :encoder chopped-codec :decoder response-chopped-codec}))
(receive-all @client (fn [msg] (.println System/out (str msg))))
(enqueue @client [:uuid 10 ["ass" "hole"]])
(enqueue @client [:uuid 10 ["ass" "hole"]])
(Thread/sleep 1000)
(server) ;disconnect
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment