Bladeren bron

fix onWebSocket***

walkor 10 jaren geleden
bovenliggende
commit
69d5bf9d17
1 gewijzigde bestanden met toevoegingen van 7 en 4 verwijderingen
  1. 7 4
      Workerman/Protocols/Websocket.php

+ 7 - 4
Workerman/Protocols/Websocket.php

@@ -115,7 +115,8 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
                 // 如果有设置onWebSocketClose回调,尝试执行
                 if(isset($connection->onWebSocketClose))
                 {
-                    call_user_func(array($connection, 'onWebSocketClose'), $connection);
+                    $func = $connection->onWebSocketClose;
+                    call_user_func($func, $connection);
                 }
                 // 默认行为是关闭连接
                 else
@@ -128,12 +129,13 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
                 // 如果有设置onWebSocketPing回调,尝试执行
                 if(isset($connection->onWebSocketPing))
                 {
-                    call_user_func(array($connection, 'onWebSocketPing'), $connection);
+                    $func = $connection->onWebSocketPing;
+                    call_user_func($func, $connection);
                 }
                 // 默认发送pong
                 else 
                 {
-                    $connection->send(pack('H*', '8a00'));
+                    $connection->send(pack('H*', '8a00'), true);
                 }
                 // 从接受缓冲区中消费掉该数据包
                 if(!$data_len)
@@ -147,7 +149,8 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
                 // 如果有设置onWebSocketPong回调,尝试执行
                 if(isset($connection->onWebSocketPong))
                 {
-                    call_user_func(array($connection, 'onWebSocketPong'), $connection);
+                    $func = $connection->onWebSocketPong;
+                    call_user_func($func, $connection);
                 }
                 // 从接受缓冲区中消费掉该数据包
                 if(!$data_len)