Fork me on GitHub
#aleph
<
2019-02-06
>
Roman Tsopin06:02:47

I have a raw tcp protocol, which writes arbitrary length string to the client, and then closes the connection. What is the simplest way to write a client in aleph? Should I read messages from stream until it’s drained and then assemble the whole response? Or is there a better way

mccraigmccraig09:02:06

@romantsopin i would (manifold.stream/reduce conj [] <stream>) the stream into a response buffer... i've not used the aleph tcp client though - do you get chunks on the stream or bytes ? if it's chunks then you would need to concatenate them too, if it's bytes you might want to use a ByteArrayOutputStream or something for more efficient collection (then a vector)

Roman Tsopin10:02:33

Thanks, I will try it. I got bytes on the stream

Roman Tsopin11:02:18

Also, am I correct, that manifold messages for tcp is just arbitrary slices of tcp stream? And written string could be potentially splitted across different messages? And for websocket every manifold message 1to1 corresponds to websocket message

kachayev11:02:32

@romantsopin Websocket has framed format for transmitting messages, meaning you can understand where message starts/ends and if it has continuations. This structure is translated into text, binary, close etc frames. If you want to do the same for arbitrary TCP, you need to explicitly tell what the “message” means, otherwise it’s just a raw stream of bytes. For arbitrary length strings it makes sense to write length of the message in known format, like i32 or i64, after that writes the string, goto “begin”.

Roman Tsopin11:02:47

Yep, thanks, just wanted to make sure I have correct assumptions about manifold abstraction in that case. Unfortunately I can’t control server protocol, it could signals end of the stream only by closing the connection, which is not very convenient. I think something like read until stream is closed (readAllBytes) could be convenient in that particular case..

Roman Tsopin11:02:30

It’s a bit off topic but is this library still supported? I’m asking because repo is archived now

kachayev11:02:42

I don’t know, I’ve never used it. I’ve just share this as an example of how strings of arbitrary length are typically encoded to be represented as a “message”