<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # ws client swoole_http_client調用upgrade,發起WebSocket握手請求,并將連接升級為WebSocket。 ~~~ function swoole_http_client->upgrade(string $path, callable $callback); ~~~ * $path URL路徑 * $callback 握手成功或失敗后回調此函數 * 使用Upgrade方法必須設置onMessage回調函數 **使用實例** ~~~ $cli = new swoole_http_client('127.0.0.1', 9501); $cli->on('message', function ($_cli, $frame) { var_dump($frame); }); $cli->upgrade('/', function ($cli) { echo $cli->body; $cli->push("hello world"); }); ~~~ **onMessage回調** ~~~ function onMessage(swoole_http_client $client, swoole_websocket_frame $frame); ~~~ * $client 客戶端對象,可調用push方法向服務器發送數據 * $frame WebSocket數據幀,可參考 swoole_websocket_server->onMessage **異步websocket客戶端** ```php class Ws { public $parse_host; public $parse_port; public $client; public $onMessage = null; public $onConnect = null; public $onClose = null; public $upgrade = null; public function __construct($host) { $this->onMessage = function(){}; $this->upgrade = function(){}; $this->onClose = function(){}; $this->onConnect = function(){}; $this->parse_url_to_array($host); } public function parse_url_to_array($url) { $parsed_arr = parse_url($url); $this->parse_host = isset($parsed_arr['host']) ? $parsed_arr['host'] : '127.0.0.1'; $this->parse_port = isset($parsed_arr['port']) ? $parsed_arr['port'] : '80'; } public function connect() { $this->client = $client = new \Swoole\Http\Client($this->parse_host, $this->parse_port); //設置事件回調函數 $this->client->on("message", $this->onMessage); $this->client->on("connect", $this->onConnect); $this->client->on("close", $this->onClose); $this->client->upgrade('/', $this->upgrade); } } $url = 'laychat.workerman.net:9292'; $tcp = new Ws($url); $tcp->onConnect = function (Client $client) { var_dump($client); }; $tcp->onMessage = function (Client $client,$data) { $client->push('{"type":"ping"}'); var_dump($data); }; $tcp->connect();
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看