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