-
-
Save joshrotenberg/1421769 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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