walkor 11 yıl önce
ebeveyn
işleme
95bbde93f8

+ 14 - 5
applications/Statistics/Modules/admin.php

@@ -6,23 +6,32 @@ function admin()
     switch($act)
     {
         case 'detect_server':
+            // 创建udp socket
             $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
             socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, 1);
             $buffer = json_encode(array('cmd'=>'REPORT_IP'))."\n";
+            // 广播
             socket_sendto($socket, $buffer, strlen($buffer), 0, '255.255.255.255', \Statistics\Web\Config::$ProviderPort);
+            // 超时相关
             $time_start = microtime(true);
-            $time_out = 2;
+            $global_timeout = 1;
             $ip_list = array();
-            while(microtime(true) - $time_start < $time_out)
+            $recv_timeout = array('sec'=>0,'usec'=>8000);
+            socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$recv_timeout);
+            
+            // 循环读数据
+            while(microtime(true) - $time_start < $global_timeout)
             {
                 $buf = $host = $port = '';
-                if(socket_recvfrom($socket, $buf, 65535, 0, $host, $port))
+                if(@socket_recvfrom($socket, $buf, 65535, 0, $host, $port))
                 {
                     $ip_list[$host] = $host;
-                    echo $buf;
-                    var_export($ip_list);
                 }
             }
             break;
     }
+    
+    include ST_ROOT . '/Views/header.tpl.php';
+    include ST_ROOT . '/Views/main.tpl.php';
+    include ST_ROOT . '/Views/footer.tpl.php';
 }

+ 3 - 3
applications/Statistics/Web/_init.php

@@ -1,5 +1,5 @@
 <?php
 define('ST_ROOT', realpath(dirname(__FILE__) . '/..'));
-require_once ST_ROOT .'Lib/functions.php';
-require_once ST_ROOT .'Lib/Cache.php';
-require_once ST_ROOT .'Web/config.php';
+require_once ST_ROOT .'/Lib/functions.php';
+require_once ST_ROOT .'/Lib/Cache.php';
+require_once ST_ROOT .'/Web/config.php';

+ 1 - 1
workers/StatisticProvider.php

@@ -100,7 +100,7 @@ class StatisticProvider extends Man\Core\SocketWorker
         }
         
         // 回应
-        return stream_socket_sendto($this->broadcastSocket, json_encode(array('result'=>ok)), 0, $address);
+        return stream_socket_sendto($this->broadcastSocket, json_encode(array('result'=>'ok')), 0, $address);
     }
     
     /**