Skip to content

Instantly share code, notes, and snippets.

@aphyr
Created December 2, 2011 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aphyr/1420958 to your computer and use it in GitHub Desktop.
Save aphyr/1420958 to your computer and use it in GitHub Desktop.
(ns ufold.core)
(use 'lamina.core 'aleph.tcp 'gloss.core)
(require 'gloss.io)
(use 'protobuf)
(defprotobuf Msg Ufold$Msg)
(defn dump-bytes [bytes]
(prn (seq bytes)))
(defn decode [s]
(let [bytearray (.array (gloss.io/contiguous s))]
(prn "decode")
(dump-bytes bytearray)
(prn (protobuf-load Msg bytearray))
(get (protobuf-load Msg bytearray) :foo)))
(defn encode [message]
(prn "encode")
(dump-bytes (protobuf-dump (protobuf Msg :foo message)))
(protobuf-dump (protobuf Msg :foo message)))
(defn echo-handler [channel client-info]
(receive-all channel (fn [buffer]
(let [msg (decode buffer)]
(enqueue channel (encode msg))))))
(defn start-server []
(start-tcp-server echo-handler
{:port 5555,
:frame (finite-block :int32)}))
(defn start-client []
(wait-for-result
(tcp-client {
:host "localhost",
:port 5555,
:frame (finite-block :int32)})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment