I have been trying to understand and write a simple client program that connects to a remote ncat instance. It is supposed to be able to read messages from the ncat instance and also send messages to the ncat instance. The requirements will be that the read and write halves will be in infinite loops and I will terminate the program using Ctrl + C.
Previously I started a similar thread on using native_tls on TcpStream but I realized I did not even get the normal unencrypted TCP session done correctly.
I followed other users' suggestions and did some reading on async/await etc but still cannot seem to get it done properly.
Current issues
I can receive messages from ncat but cannot send messages to ncat.
Is there a standard/commonly accepted way to write such network programs (that also use TLS) that I can refer to?
One main issue is that reading/writing to stdin/stdout would block?
In async code, the read_pipe will have to finish first before write_pipe. This implies that nothing will get written until the read_pipe function finishes. The solution here is to instead use futures::try_join (which runs both futures). Take a look here: futures::try_join - Rust
You could also use join instead of try_join; the difference is that try_join immediantly stops once an error is returned from either future.