This might be a more full example of lamina + aleph + gloss for the docs?

101 views
Skip to first unread message

Andrew Cholakian

unread,
Jun 11, 2012, 12:12:46 PM6/11/12
to alep...@googlegroups.com
So, I thought this might be useful. I needed to add a bidirectional communication protocol to my engulf project (I'm adding remote workers). I considered using websockets, but in the new aleph the client/server don't seem to play along well with each other, and it's really overkill for server to server communications. So, I wound up writing a simple framed TCP service in aleph/lamina/gloss. The docs, however, aren't so complete wrt this stuff, so I thought that this code could be useful to others. Zach, if it checks out with you I could add more annotations to it and send it in as a pull request to aleph perhaps as an example? Or maybe it could be useful in the wiki?

One thing that I found missing from practical examples was the use of 'to-buf-seq' and 'contiguous' in gloss when using binary formats (I'm using jackson's SMILE, binary JSON format).

The source can be found here:

A very bare test suite can be found here:

Marc Haemmerle

unread,
Aug 24, 2012, 5:44:24 PM8/24/12
to alep...@googlegroups.com
I stumbled over the same problem as Andrew in that the incoming frame/buffer is prepended with 4 bytes. As long as I'm only prototyping it's ok to cut them away, but as soon as I start benchmarking it would be nice to not have exceptions flying around at that point.

Is this a bug or are we doing something horribly wrong?

Andrew Cholakian

unread,
Aug 24, 2012, 5:52:59 PM8/24/12
to alep...@googlegroups.com

I'll add that on larger frames the 4 bytes disappear. This may be a bug

Zach Tellman

unread,
Aug 24, 2012, 5:53:22 PM8/24/12
to alep...@googlegroups.com
Marc,

You're seeing this in your own codebase, or you also saw it when using
engulf? If it's the former, is your code available for examination?

Zach

Zach Tellman

unread,
Aug 24, 2012, 5:58:49 PM8/24/12
to alep...@googlegroups.com
Oh, I think I see the issue. (.array buf) returns the backing array,
which is not necessarily the same dimension as the buffer. If, for
instance, you trim off the first four bytes, the backing array will
still contain them.

I'm looking at the implementation in aleph.formats, and it also has
this same bug, so I apologize if that's where you were getting the
approach from. It should look like:

(let [ary (byte-array (.remaining buf))]
(.get buf ary)
ary)

I'll be fixing aleph.formats to reflect this.

Zach

Marc Haemmerle

unread,
Aug 24, 2012, 6:14:36 PM8/24/12
to alep...@googlegroups.com
It was in my own code, which was looking similar to engulf's in that regard: simple tcp server/client setup which exchanges binary messages.

Thanks for fixing it!

Cheers,
Marc

Andrew Cholakian

unread,
Aug 26, 2012, 11:25:45 AM8/26/12
to alep...@googlegroups.com
Thanks zach! Is 'buf' in your example the result of (contiguous frame) ?

Zach Tellman

unread,
Aug 26, 2012, 3:16:01 PM8/26/12
to alep...@googlegroups.com
Yeah, it's the contiguous buffer. 


Reply all
Reply to author
Forward
0 new messages