Commit e956da63 by xgrowingpains

init

parents
Pipeline #4502 failed with stages
in 0 seconds
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "tcpclient"
version = "0.1.0"
[package]
name = "tcpclient"
version = "0.1.0"
authors = ["subroot"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
use std::io::{self, prelude::*, BufReader, Write};
use std::net::TcpStream;
use std::str;
fn main() -> std::io::Result<()> {
//连接server
let mut stream = TcpStream::connect("127.0.0.1:8080")?;
//打印连接
eprintln!("stream ==={:?}", stream);
//循环
for _ in 0..10 {
//初始化输入
let mut input = String::new();
//接收输入内容
io::stdin().read_line(&mut input).expect("Failed to read from stdin");
//打印输入内容
eprintln!("input ==={:?}", input);
//以数组传输
stream.write(input.as_bytes()).expect("Failed to write to stream");
//读取返回值
let mut reader = BufReader::new(&stream);
//初始化buffer
let mut buffer: Vec<u8> = Vec::new();
//格式化回车
reader.read_until(b'\n', &mut buffer) .expect("Could not read into buffer");
//转字符串
println!("{}", str::from_utf8(&buffer).expect("Could not write buffer as string"));
println!("");
}
Ok(())
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment