为什么 Tokio Hello World 会出现 "No connection could be made because the target machine actively refused it" 恐慌?
Why does the Tokio Hello World panic with "No connection could be made because the target machine actively refused it"?
这是示例 hello world 程序 from the Tokio documentation 。
use tokio::prelude::*;
#[tokio::main]
async fn main() {
let mut stream = TcpStream::connect("127.0.0.1:6142").await.unwrap();
println!("created stream");
let result = stream.write(b"hello world\n").await;
println!("wrote to stream; success={:?}", result.is_ok());
}
这给了我这个错误:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 10061, kind: ConnectionRefused, message: "No connection could be made because the target machine actively refused it." }', src\libcore\result.rs:1165:5
stack backtrace:
.
.
.
我该如何解决?
您似乎没有按照 hello world 的说明进行操作,因此出现错误,因为没有服务器在侦听:
Install socat
, which is a network utility that we’ll use to simulate a server. Then type the following command to print out everything that is received on port 6142 (a somewhat arbitrary number we have chosen for this example):
socat TCP-LISTEN:6142,fork stdout
这是示例 hello world 程序 from the Tokio documentation 。
use tokio::prelude::*;
#[tokio::main]
async fn main() {
let mut stream = TcpStream::connect("127.0.0.1:6142").await.unwrap();
println!("created stream");
let result = stream.write(b"hello world\n").await;
println!("wrote to stream; success={:?}", result.is_ok());
}
这给了我这个错误:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 10061, kind: ConnectionRefused, message: "No connection could be made because the target machine actively refused it." }', src\libcore\result.rs:1165:5
stack backtrace:
.
.
.
我该如何解决?
您似乎没有按照 hello world 的说明进行操作,因此出现错误,因为没有服务器在侦听:
Install
socat
, which is a network utility that we’ll use to simulate a server. Then type the following command to print out everything that is received on port 6142 (a somewhat arbitrary number we have chosen for this example):socat TCP-LISTEN:6142,fork stdout