/** * Send message to the websocket * * @access public * @param int $type * @param int $id * @param int $endpoint * @param string $message * @return ElephantIO\Client */ public function send($type, $id = null, $endpoint = null, $message = null) { if (!is_int($type) || $type > 8) { throw new \InvalidArgumentException('ElephantIOClient::send() type parameter must be an integer strictly inferior to 9.'); } $raw_message = $type . ':' . $id . ':' . $endpoint . ':' . $message; $payload = new Payload(); $payload->setOpcode(Payload::OPCODE_TEXT)->setMask(true)->setPayload($raw_message); $encoded = $payload->encodePayload(); fwrite($this->fd, $encoded); // wait 100ms before closing connexion usleep(100 * 1000); $this->stdout('debug', 'Sent ' . $raw_message); return $this; }
/** * Send message to the websocket * @param int $type * @param string $message * @param int $id * @param int $endpoint * @return Client * @throws \InvalidArgumentException * @throws \RuntimeException */ public function send($type, $message = NULL, $id = NULL, $endpoint = NULL) { if (!is_int($type) || $type > 8) { throw new \InvalidArgumentException('ElephantIOClient::send() type parameter must be an integer strictly inferior to 9.'); } $raw_message = $type . ':' . $id . ':' . $endpoint . ':' . $message; $payload = new Payload(); $payload->setOpcode(Payload::OPCODE_TEXT)->setMask(TRUE)->setPayload($raw_message); $encoded = $payload->encodePayload(); $res = @fwrite($this->fd, $encoded); if ($res === 0) { $error = error_get_last(); throw new \RuntimeException($error['message'], $error['code']); } return $this; }
/** * @param $message * @param int $opCode * @param bool $mask * * @return string */ private function encode($message, $opCode = Payload::OPCODE_TEXT, $mask = true) { $payload = new Payload(); return $payload->setOpcode($opCode)->setMask($mask)->setPayload($message)->encodePayload(); }
/** * Send message to the websocket * * @access public * @param int $type * @param int $id * @param int $endpoint * @param string $message * @return ElephantIO\Client */ public function send($type, $ns = null, $event = null, $data = null) { if (!is_int($type)) { throw new \InvalidArgumentException('ElephantIOClient::send() type parameter must be an integer strictly inferior to 9.'); } /*$raw_message = $type.':'.$id.':'.$endpoint.':'.$message;*/ $raw_message = $type; if ($ns && $ns != '/') { $raw_message .= $ns; } if ($event) { $raw_message .= ',["' . $event . '"'; if (!empty($data)) { $raw_message .= ',' . json_encode($data); } $raw_message .= ']'; } $payload = new Payload(); $payload->setOpcode(Payload::OPCODE_TEXT)->setMask(true)->setPayload($raw_message); $encoded = $payload->encodePayload(); if (is_resource($this->fd)) { fwrite($this->fd, $encoded); // wait 100ms before closing connection usleep(100 * 1000); $this->log('debug', 'Sent ' . $raw_message); } return $this; }