Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
ws-rst
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qlintonger xeno
ws-rst
Commits
52096436
Commit
52096436
authored
Feb 07, 2025
by
qlintonger xeno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
setup-first-done+1
parent
007799d2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
4 deletions
+3
-4
src/client.rs
+3
-4
No files found.
src/client.rs
View file @
52096436
...
@@ -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!
(
"无法获取连接参数"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment