如何处理 TcpStream 上的并行读取和写入? [英] How do I handle parallel reads and writes on a TcpStream?
本文介绍了如何处理 TcpStream 上的并行读取和写入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读了惯用的方式在等待读取时处理写入 TcpStream,但我仍然不确定如何处理.我正在通过 Telnet 连接到 Rust 二进制文件,并想发送命令"并接收状态".几乎就像一个简单的回显服务器.
I read Idiomatic way to handle writes to a TcpStream while waiting on read, but I'm still unsure of how to handle this. I'm connecting to a Rust binary via Telnet and would like to send "commands" and receive "status". Almost like a simple echo server.
推荐答案
我结束了 克隆流,它工作正常:
I ended up cloning the stream and it's working fine:
let second_stream = stream.try_clone().expect("Cannot clone stream");
let mut reader = BufferedReader::new(second_stream);
let mut writer = BufferedWriter::new(stream);
这篇关于如何处理 TcpStream 上的并行读取和写入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文