send() public method

发送数据
public send ( string $data ) : boolean | integer
$data string
return boolean | integer | int
Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
 /**
  * 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;
     }
     return $this->socket->send($this->hybi10Encode($data, $type, $masked));
 }