rust tcp客户端
use std::net::TcpStream;
use std::str;
use std::io::{self, BufRead, BufReader, Read, Write};
fn main() {
let stream = TcpStream::connect("127.0.0.1:8888").expect("Could not connect Server");
loop {
let mut input = String::new();
let mut buffer:Vec<u8>=Vec::new();
io::stdin().read_line(&mut input).expect("Failed to write to server");
let mut reader = BufReader::new(&stream);
reader.read_until(b'\n',&mut buffer).expect("could not read info buffer");
println!("{}",str::from_utf8(&buffer).expect("Could not write buffer as string"));
}
}
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 ggchzzz@163.com