xy 3 tygodni temu
rodzic
commit
25e46bd4d5
1 zmienionych plików z 7 dodań i 1 usunięć
  1. 7 1
      src/client.php

+ 7 - 1
src/client.php

@@ -82,6 +82,7 @@ class GameClient {
             echo "是否成功获取信息: " .$userResponse->hasUserInfo() . "\n";
             if ($userResponse->hasUserInfo()) {
                 $this->enterHall($userResponse->getUserInfo()->getUserId());
+                $this->startListening();
             }
             
         } catch (Exception $e) {
@@ -100,10 +101,15 @@ class GameClient {
             echo "成功进入大厅!\n";
             echo "大厅玩家数: " . $response->getSuccess() . "\n";
         });
+    }
 
+    private function startListening() {
+        if (!$this->client) {
+            throw new Exception("WebSocket连接未建立");
+        }
+        echo "开始监听WebSocket消息...\n";
         $this->client->startListening();
     }
-
     private function enterHall($userId) {
         if (!$this->client) {
             throw new Exception("WebSocket连接未建立");