Compare commits

...

2 Commits

Author SHA1 Message Date
WoNiu 525e10badc Merge branch 'Dev' into 主控 2024-04-06 17:01:09 +08:00
WoNiu 229965a3c9 登录被顶 超时 2024-04-06 17:00:54 +08:00
1 changed files with 12 additions and 8 deletions

View File

@ -45,6 +45,7 @@ class LoginSocket{
connect() async { connect() async {
socket?.close(); socket?.close();
socket = await Socket.connect(url, port, timeout: const Duration(seconds: 30)); socket = await Socket.connect(url, port, timeout: const Duration(seconds: 30));
heartTime = DateTime.now().millisecondsSinceEpoch;
socket?.listen((event) { socket?.listen((event) {
@ -58,6 +59,11 @@ class LoginSocket{
// //
if (data['op'] == 4){ if (data['op'] == 4){
try{ try{
//
heartTime = DateTime.now().millisecondsSinceEpoch;
//
int time = data['time']; int time = data['time'];
time = DateTime.now().millisecondsSinceEpoch - time; time = DateTime.now().millisecondsSinceEpoch - time;
if(time> (3 * 60 * 1000) ){ // > 3 if(time> (3 * 60 * 1000) ){ // > 3
@ -107,17 +113,17 @@ class LoginSocket{
/// ///
heartbeat(){ heartbeat(){
DateTime now = DateTime.now();
int timestamp = now.millisecondsSinceEpoch; //
heartTime = timestamp;
Timer(const Duration(seconds: 20), () async { Timer(const Duration(seconds: 20), () async {
if (socket == null){ final time = DateTime.now().millisecondsSinceEpoch - heartTime;
// if(time > (3 * 60 * 1000) ){ // > 3
await connect(); socketError();
return;
} }
heartbeat();
Map map = { Map map = {
"op": 3, "op": 3,
}; };
@ -125,8 +131,6 @@ class LoginSocket{
socket?.add(dataMake(map)); socket?.add(dataMake(map));
socket?.flush(); socket?.flush();
heartbeat();
}); });
} }