Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on Read all data from TCP stream in Rust
Post
Read all data from TCP stream in Rust
I'd like to write a TCP client in Rust that can receive the entire message sent by a server, but I have no information about the length of a message.
I'm aware that TCP doesn't preserve message boundaries.
Still, what's the best I can do to read the entire message from the TcpStream
?
In the scenario the client should work, there's no protocol for the messages sent from server to client: The client doesn't know beforehand how many bytes are in a message and the message doesn't have a header (as in HTTP) that would contain the message length. There's no special delimiter that marks the end of a message.
Also, the server might keep the TCP connection open after sending a message, meaning I can not rely on every message being completed with a server FIN.
I'd like to do this using Rust's standard library only, no other dependencies.
1 comment thread