Exemple #1
0
function my_onReceive($serv, $fd, $from_id, $data)
{
    //file_put_contents('/tmp/log', getmypid() . "\t" . memory_get_usage() . "\t" . memory_get_usage(true) . "\n", FILE_APPEND);
    //$request = http_parse($data);
    $data = "it work!";
    $data = http_package($data);
    swoole_server_send($serv, $fd, $data);
    swoole_server_close($serv, $fd, $from_id);
}
 public static function sendOne_bak($fd, $cmd, $data)
 {
     if (empty(self::$serv) || empty($fd) || empty($cmd)) {
         return;
     }
     $result = array('e_no' => -1, 'e_msg' => '', 'cmd' => $cmd, 'data' => $data, '_fd' => $fd);
     //$data = json_encode(array($cmd, $data));
     $data = json_encode($result);
     return \swoole_server_send(self::$serv, $fd, $data);
 }
Exemple #3
0
 public function onReceive()
 {
     $params = func_get_args();
     $data = trim($params[3]);
     if (empty($data)) {
         return;
     }
     if ('<policy' == substr($data, 0, 7)) {
         \swoole_server_send($params[0], $params[1], "<cross-domain-policy>\n                    <allow-access-from domain='*' to-ports='*' />\n                    </cross-domain-policy>");
     }
 }
Exemple #4
0
 public function onReceive()
 {
     $params = func_get_args();
     $data = trim($params[3]);
     $serv = $params[0];
     $fd = $params[1];
     echo "get data {$data} from {$fd}\n";
     if (empty($data)) {
         return;
     }
     $server = Protocol\Factory::getInstance(Core\Config::getField('socket', 'protocol'));
     $result = $server->parse($data);
     if (empty($result['a'])) {
         \swoole_server_send($serv, $fd, "server:" . $data);
     } else {
         $server->setFd($fd);
         $server = $this->route($server);
         \swoole_server_send($serv, $fd, $server->getData());
     }
 }
Exemple #5
0
 public function send($client_id, $data)
 {
     swoole_server_send($this->sw, $client_id, $data);
 }
Exemple #6
0
 public function sendOne($serv, $fd, $cmd, $data)
 {
     if (empty($serv) || empty($fd) || empty($cmd)) {
         return;
     }
     //echo "send {$fd} cmd: {$cmd}, len:".json_encode($data).PHP_EOL;
     $data = json_encode(array($cmd, $data));
     return \swoole_server_send($serv, $fd, $data);
 }
 /**
  * 发送数据
  * @param int $fd   连接的文件描述符
  * @param string $data  发送的数据
  */
 function send($fd, $data, $mask = TRUE)
 {
     if ($mask) {
         $data = $this->mask($data);
     }
     return swoole_server_send($this->server, $fd, $data);
 }
 private function sendOne($serv, $fd, $data)
 {
     \swoole_server_send($serv, $fd, $data);
 }