Răsfoiți Sursa

onGatewayConnect 支持参数Client_id

liangl 11 ani în urmă
părinte
comite
53f57cc7b2

+ 1 - 1
applications/Demo/Bootstrap/BusinessWorker.php

@@ -120,7 +120,7 @@ class BusinessWorker extends Man\Core\SocketWorker
             switch($cmd)
             {
                 case GatewayProtocol::CMD_ON_GATEWAY_CONNECTION:
-                    call_user_func_array(array('Event', 'onGatewayConnect'), array());
+                    call_user_func_array(array('Event', 'onGatewayConnect'), array(Context::$client_id));
                     break;
                 case GatewayProtocol::CMD_ON_MESSAGE:
                     call_user_func_array(array('Event', 'onMessage'), array(Context::$client_id, $pack->body));

+ 4 - 2
applications/Demo/Event.php

@@ -6,6 +6,7 @@
  * 可以开启多个telnet窗口,窗口间可以互相聊天
  * 
  * websocket协议的聊天室见workerman-chat及workerman-todpole
+ * 
  * @author walkor <workerman.net>
  */
 
@@ -19,9 +20,10 @@ use \Protocols\TextProtocol;
 class Event
 {
     /**
-     * 当网关有客户端链接上来时触发,一般这里留空
+     * 当网关有客户端链接上来时触发,每个客户端只触发一次,如果不许要任何操作可以不实现此方法
+     * 这里当客户端一连上来就给客户端发送输入名字的提示
      */
-    public static function onGatewayConnect()
+    public static function onGatewayConnect($client_id)
     {
         Gateway::sendToCurrentClient(TextProtocol::encode("type in your name:"));
     }