lizhen_gitee 1 gadu atpakaļ
vecāks
revīzija
326f860c1b

+ 4 - 1
application/chat/Events.php

@@ -23,7 +23,7 @@
  * 聊天主逻辑
  * 主要是处理 onMessage onClose 
  */
-//use \GatewayWorker\Lib\Gateway;
+use \GatewayWorker\Lib\Gateway;
 //use \GatewayWorker\Lib\DbConnection;
 use think\Db;
 use think\App;
@@ -48,6 +48,9 @@ class Events
          //echo $message.PHP_EOL;
          //file_put_contents('1.json',$message.PHP_EOL,FILE_APPEND);
          $info = Db::name('gateway_test')->insertGetId(['msg'=>'[msg]'.$message,'datetime'=>date('Y-m-d H:i:s')]);
+
+         Gateway::sendToAll($client_id.'说:'.$message);
+
          return;
 
         /* $message = json_decode($message,true);

+ 1 - 1
application/chat/start_gateway.php

@@ -27,7 +27,7 @@ $gateway->count = 4;
 $gateway->lanIp = '127.0.0.1';
 // 内部通讯起始端口。假如$gateway->count=4,起始端口为2300
 // 则一般会使用2300 2301 2302 2303 4个端口作为内部通讯端口 
-$gateway->startPort = 2347;
+$gateway->startPort = 2350;
 // 心跳间隔
 $gateway->pingInterval = 10;
 // 心跳数据

+ 17 - 0
application/index/controller/Test.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace app\index\controller;
+
+use think\Controller;
+
+use \GatewayWorker\Lib\Gateway;
+class Test extends Controller
+{
+    public function test(){
+
+        $Gateway = new Gateway();
+        $Gateway::$registerAddress = '127.0.0.1:2345';
+        $Gateway::sendToAll('来自服务端的主动推送'.date('Y-m-d H:i:s'));
+
+    }
+}