/** * send string data * @param $data * @param string $type * @param bool $masked * @throws \Exception * @return bool */ public function send($data, $type = 'text', $masked = true) { if (empty($data)) { throw new \Exception("data is empty"); } if (!$this->handshake) { trigger_error("not complete handshake."); return false; } if ($this->haveSwooleEncoder) { switch ($type) { case 'text': $_type = WEBSOCKET_OPCODE_TEXT; break; case 'binary': case 'bin': $_type = WEBSOCKET_OPCODE_BINARY; break; default: return false; } $_send = \swoole_websocket_server::pack($data, $_type); } else { $_send = $this->hybi10Encode($data, $type, $masked); } return $this->socket->send($_send); }
/** * @param string $data * @param string $type * @param bool $masked * @return bool */ public function send($data, $type = 'text', $masked = false) { switch ($type) { case 'text': $_type = WEBSOCKET_OPCODE_TEXT; break; case 'binary': case 'bin': $_type = WEBSOCKET_OPCODE_BINARY; break; default: return false; } return $this->socket->send(swoole_websocket_server::pack($data, $_type, true, $masked)); }
/** * send string data * @param $data * @param string $type * @param bool $masked * @throws \Exception */ public function send($data, $type = self::OP_TEXT) { $data = \swoole_websocket_server::pack($data, $type); $this->_client->send($data); }