From 95a4af55db6d9bac1b8ab0b8aafcefa6d1386ec9 Mon Sep 17 00:00:00 2001 From: sa0ChunLuyu Date: Sun, 30 Oct 2022 22:51:42 +0800 Subject: [PATCH] no message --- Applications/YourApp/Events.php | 3 ++- Applications/YourApp/start_gateway.php | 2 +- config.php | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Applications/YourApp/Events.php b/Applications/YourApp/Events.php index 2b9f97b..0e1026f 100644 --- a/Applications/YourApp/Events.php +++ b/Applications/YourApp/Events.php @@ -51,7 +51,8 @@ class Events */ public static function onMessage($client_id, $message) { - + global $config; + if ($message == $config['ping']) Gateway::sendToClient($client_id, $config['pang']); } /** diff --git a/Applications/YourApp/start_gateway.php b/Applications/YourApp/start_gateway.php index c1c0306..65af45c 100644 --- a/Applications/YourApp/start_gateway.php +++ b/Applications/YourApp/start_gateway.php @@ -40,7 +40,7 @@ $gateway->registerAddress = '127.0.0.1:' . $config['register']; // 心跳间隔 //$gateway->pingInterval = 10; // 心跳数据 -$gateway->pingData = '{"action":"ping"}'; +$gateway->pingData = $config['ping']; /* // 当客户端连接上来时,设置连接的onWebSocketConnect,即在websocket握手时的回调 diff --git a/config.php b/config.php index 158714a..a693468 100644 --- a/config.php +++ b/config.php @@ -8,6 +8,10 @@ $config = [ 'register' => 3238, // 内部通讯起始端口 'start' => 3900, + // 心跳收 + 'ping' => '{"action":"ping"}', + // 心跳回 + 'pang' => '{"action":"pang"}', // 退出接口 'close' => '', ]; \ No newline at end of file