I have the following code with works on the client and server . The client code just sends the frame ( even though it is using tcp_write_all ) and the Server reads the frame .
There is no ACK from the Server to the client
I want to modify this code so that the server will send an ACK on receiving the frame to the client . The client should wait for the ACK before sending the next frame.
How should I start implementing this ? Should I do a split of the tcpStream or is there a different way ?
Client
fn write_frame(mut tcp: TcpStream, buf1: &Bytes, filename: &str) -> TcpStream {
.....
....`
tcp.write_all(
&buf1
[current_pointer..(current_pointer + data_field_size + data_frame_length as usize)],
);
}
Server
async fn process(stream: TcpStream, tid: u32) -> Result<(), Box<dyn Error>> {
.....
....
let mut framed = LengthDelimitedCodec::builder()
.length_field_offset(0) // length of hdr1
.length_field_length(4)
.length_adjustment(0) // length of hdr2
.num_skip(4) // leaving the header byte , Does not work if 0
.new_read(stream);
while let Some(request) = framed.next().await {
...
...
}