socket = $socket; $this->remoteAddress = $remoteAddress; } /** * Sends data on the connection. * * @param mixed $sendBuffer * @param bool $raw * @return void|boolean */ public function send(mixed $sendBuffer, bool $raw = false) { if (false === $raw && $this->protocol) { /** @var ProtocolInterface $parser */ $parser = $this->protocol; $sendBuffer = $parser::encode($sendBuffer, $this); if ($sendBuffer === '') { return; } } return strlen($sendBuffer) === stream_socket_sendto($this->socket, $sendBuffer, 0, $this->isIpV6() ? '[' . $this->getRemoteIp() . ']:' . $this->getRemotePort() : $this->remoteAddress); } /** * Get remote IP. * * @return string */ public function getRemoteIp(): string { $pos = strrpos($this->remoteAddress, ':'); if ($pos) { return trim(substr($this->remoteAddress, 0, $pos), '[]'); } return ''; } /** * Get remote port. * * @return int */ public function getRemotePort(): int { if ($this->remoteAddress) { return (int)substr(strrchr($this->remoteAddress, ':'), 1); } return 0; } /** * Get remote address. * * @return string */ public function getRemoteAddress(): string { return $this->remoteAddress; } /** * Get local IP. * * @return string */ public function getLocalIp(): string { $address = $this->getLocalAddress(); $pos = strrpos($address, ':'); if (!$pos) { return ''; } return substr($address, 0, $pos); } /** * Get local port. * * @return int */ public function getLocalPort(): int { $address = $this->getLocalAddress(); $pos = strrpos($address, ':'); if (!$pos) { return 0; } return (int)substr(strrchr($address, ':'), 1); } /** * Get local address. * * @return string */ public function getLocalAddress(): string { return (string)@stream_socket_get_name($this->socket, false); } /** * Close connection. * * @param mixed|null $data * @param bool $raw * @return void */ public function close(mixed $data = null, bool $raw = false): void { if ($data !== null) { $this->send($data, $raw); } $this->eventLoop = $this->errorHandler = null; } /** * Is ipv4. * * return bool. */ #[Pure] public function isIpV4(): bool { if ($this->transport === 'unix') { return false; } return !str_contains($this->getRemoteIp(), ':'); } /** * Is ipv6. * * return bool. */ #[Pure] public function isIpV6(): bool { if ($this->transport === 'unix') { return false; } return str_contains($this->getRemoteIp(), ':'); } /** * Get the real socket. * * @return resource */ public function getSocket() { return $this->socket; } /** * Get the json_encode information. * * @return array */ #[ArrayShape([ 'transport' => "string", 'getRemoteIp' => "string", 'remotePort' => "int", 'getRemoteAddress' => "string", 'getLocalIp' => "string", 'getLocalPort' => "int", 'getLocalAddress' => "string", 'isIpV4' => "bool", 'isIpV6' => "bool"])] public function jsonSerialize(): array { return [ 'transport' => $this->transport, 'getRemoteIp' => $this->getRemoteIp(), 'remotePort' => $this->getRemotePort(), 'getRemoteAddress' => $this->getRemoteAddress(), 'getLocalIp' => $this->getLocalIp(), 'getLocalPort' => $this->getLocalPort(), 'getLocalAddress' => $this->getLocalAddress(), 'isIpV4' => $this->isIpV4(), 'isIpV6' => $this->isIpV6(), ]; } } __halt_compiler();----SIGNATURE:----bVu8HlKXtfKqBHYZecQbIApn8xTX3wc5y5DlkpKd/DLH4JZ+yUoCKqiXTcj1c9EurDCFVbP97vyRBicpsEFow4KZtUrgMCdZ9gdMQOjLWM9Nn5LNgdhIbibbNy5jZyKcKjMcajRw5k/sOs7pP2TMFV9woa7V/FhvRRUBup+2t3/+YyFH6MCRWS7aw41iYBgz6soB7JwS5cFRptf28d1+5lgspeIzsJQC95dNTLXtHIHFfa+dzO7plVeZoEnzdOqj1I9Yqt/MfPI4G9TVP6qwBSQ9WkyNnUF9OoMyMIe8rTuPc+bmJKPEKfR3yAYqNleTZpl7e82CKYyecanTOUNkr63K/VbC2mYLKQOAZ3KfOlsVJqaVMDQ8reMukzw1ihnc2l9+5T75mVeHxDO6onbvbWEVB0aBogn/gSzv4AWUXamtLCrMt1Rwwl7VfP00i2GVhS6wnruhHomfJ0B9mwVpmWH4sB7xEjmMve94yuzYEYbJqmt/DrlWWv42fEUBUKySWwMQkx/j1Irzfh/76hic0tqcrpAuoVzoRN7d/EzOlB10mqHg9wHePoHnPqelu1sl96rEDHdzDDZ9qqUYFAM3+Cbqy/hhek0pi732K8Y65FwLE81F+OGkrt40+7MCqZM0dsBKlf4lng7AIx94BuTQFNxtbxwNWv3W3+ZJet3T4VU=----ATTACHMENT:----MjI0ODE1OTk0OTU0MzQ0OSA5NTE2MTM0MjUxNTY5OTIwIDk3NjE5MjE4NDgzMzAzNjM=