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.
Post History
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 bo...
#4: Post edited
- 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](https://stackoverflow.com/questions/9563563/what-is-a-message-boundary#9563694).
- **Still, what's the best I can do to read the entire message from the [`TcpStream`](https://doc.rust-lang.org/std/net/struct.TcpStream.html)?**
- 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](https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Connection_termination).
I'd like to do this preferably using Rust's standard library only, no other dependencies.
- 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](https://stackoverflow.com/questions/9563563/what-is-a-message-boundary#9563694).
- **Still, what's the best I can do to read the entire message from the [`TcpStream`](https://doc.rust-lang.org/std/net/struct.TcpStream.html)?**
- 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](https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Connection_termination).
- I'd like to do this using Rust's standard library only, no other dependencies.
#1: Initial revision
Read all data from TCP stream
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](https://stackoverflow.com/questions/9563563/what-is-a-message-boundary#9563694). **Still, what's the best I can do to read the entire message from the [`TcpStream`](https://doc.rust-lang.org/std/net/struct.TcpStream.html)?** 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](https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Connection_termination). I'd like to do this preferably using Rust's standard library only, no other dependencies.