https://kotlinlang.org logo
#ktor
Title
# ktor
a

Andrew Gazelka

09/27/2020, 4:38 PM
Is there an idiomatic way using ktor native sockets to send over/receive objects?
s

Sam Garfinkel

09/27/2020, 6:33 PM
I’d recommend https://github.com/Kotlin/kotlinx.serialization, perhaps with protobuf support.
a

Andrew Gazelka

09/28/2020, 3:47 AM
@Sam Garfinkel If I send two protobufs over TCP in quick succession, when I read the byte array what I get is the concatenation of both requests. Is there a way to avoid this? (I am flushing)… I am guessing adding a byte specifying the legnth before sending each byte array?
s

Sam Garfinkel

09/28/2020, 4:53 PM
Yeah you’ll need to create a meta-message for serializing your stuff. Protobuf doesn’t handle message delimitation for you.
The easiest way is to prepend the length to each message.
3 Views