15declare(strict_types=1);
17namespace raklib\client;
22use
function socket_connect;
23use
function socket_last_error;
24use
function socket_recv;
25use
function socket_send;
26use
function socket_strerror;
32 public function __construct(
35 parent::__construct($this->connectAddress->getVersion() === 6);
37 if(!@socket_connect($this->socket, $this->connectAddress->getIp(), $this->connectAddress->getPort())){
38 $error = socket_last_error($this->socket);
39 throw new SocketException(
"Failed to connect to " . $this->connectAddress .
": " . trim(socket_strerror($error)), $error);
42 $this->
setSendBuffer(1024 * 1024 * 8)->setRecvBuffer(1024 * 1024 * 8);
46 return $this->connectAddress;
54 if(@socket_recv($this->socket, $buffer, 65535, 0) ===
false){
55 $errno = socket_last_error($this->socket);
56 if($errno === SOCKET_EWOULDBLOCK){
59 throw new SocketException(
"Failed to recv (errno $errno): " . trim(socket_strerror($errno)), $errno);
68 $result = @socket_send($this->socket, $buffer, strlen($buffer), 0);
69 if($result ===
false){
70 $errno = socket_last_error($this->socket);
71 throw new SocketException(
"Failed to send packet (errno $errno): " . trim(socket_strerror($errno)), $errno);
writePacket(string $buffer)