Commit 52096436 by qlintonger xeno

setup-first-done+1

parent 007799d2
...@@ -75,7 +75,6 @@ pub(crate) async fn handle_client(stream: tokio::net::TcpStream) -> Result<(), E ...@@ -75,7 +75,6 @@ pub(crate) async fn handle_client(stream: tokio::net::TcpStream) -> Result<(), E
if let Some(params) = connection_params { if let Some(params) = connection_params {
if let Some(from_id) = params.get("fromId") { if let Some(from_id) = params.get("fromId") {
let from_id = from_id.clone(); let from_id = from_id.clone();
let from_name = params.get("fromName").clone();
let mut last_heartbeat_time = Instant::now(); let mut last_heartbeat_time = Instant::now();
loop { loop {
...@@ -90,7 +89,7 @@ pub(crate) async fn handle_client(stream: tokio::net::TcpStream) -> Result<(), E ...@@ -90,7 +89,7 @@ pub(crate) async fn handle_client(stream: tokio::net::TcpStream) -> Result<(), E
Ok(data) => { Ok(data) => {
match data.msg_type.as_str() { match data.msg_type.as_str() {
"Heart" => { "Heart" => {
println!("收到客户端心跳消息 {}", &data); println!("收到客户端心跳消息 {:?}", &data);
handle_heartbeat(&mut last_heartbeat_time); handle_heartbeat(&mut last_heartbeat_time);
if let Ok(json_str) = make_common_resp(Default::default(), "Heart") { if let Ok(json_str) = make_common_resp(Default::default(), "Heart") {
sender.send(Message::text(json_str)).await?; sender.send(Message::text(json_str)).await?;
...@@ -119,13 +118,13 @@ pub(crate) async fn handle_client(stream: tokio::net::TcpStream) -> Result<(), E ...@@ -119,13 +118,13 @@ pub(crate) async fn handle_client(stream: tokio::net::TcpStream) -> Result<(), E
} }
// 处理心跳超时 // 处理心跳超时
_ = time::sleep_until(tokio::time::Instant::from(last_heartbeat_time + Duration::from_secs(20))) => { _ = time::sleep_until(tokio::time::Instant::from(last_heartbeat_time + Duration::from_secs(20))) => {
println!("用户id-{},用户名-{} 20秒内没有发送心跳,挂断连接", from_id, from_name); println!("用户id-{} 20秒内没有发送心跳,挂断连接", from_id);
break; break;
} }
} }
} }
println!("断开与用户id: {},用户名:{}连接", from_id, from_name); println!("断开与用户id: {},连接", from_id);
} }
} else { } else {
println!("无法获取连接参数"); println!("无法获取连接参数");
......
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