【发布时间】:2020-01-07 13:27:16
【问题描述】:
我正在学习 Actix 框架。文档有the sample:
use actix_rt::System;
use actix_web::{web, App, HttpResponse, HttpServer};
use std::sync::mpsc;
use std::thread;
#[actix_rt::main]
async fn main() {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let sys = System::new("http-server");
let srv = HttpServer::new(|| App::new().route("/", web::get().to(|| HttpResponse::Ok())))
.bind("127.0.0.1:8088")?
.shutdown_timeout(60) // <- Set shutdown timeout to 60 seconds
.run();
let _ = tx.send(srv);
sys.run()
});
let srv = rx.recv().unwrap();
// pause accepting new connections
srv.pause().await;
// resume accepting new connections
srv.resume().await;
// stop server
srv.stop(true).await;
}
编译这段代码后没有错误:
但我无法在浏览器中打开页面:
我错过了什么以及为什么页面无法在我的浏览器中打开?
【问题讨论】:
-
// stop serversrv.stop(true).await;你要停止服务器吗? -
没有。我该怎么办?我需要它吗?
-
srv.pause / srv.resume / srv.stop 的行控制着你的服务器是否正在运行。如果您想让它无限期运行,请尝试将这些行替换为
srv.await
标签: windows rust rust-actix actix-web