/** * Reads from socket and returns Buffer. * * @throws InvalidPacketException * * @return Buffer Buffer */ public function Read($Length = 1400) { $Buffer = new Buffer(); $Buffer->Set(FRead($this->Socket, $Length)); $this->ReadInternal($Buffer, $Length, [$this, 'Sherlock']); return $Buffer; }
public function Read() { $Buffer = new Buffer(); $Buffer->Set(FRead($this->RconSocket, 4)); if ($Buffer->Remaining() < 4) { throw new InvalidPacketException('Rcon read: Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY); } $PacketSize = $Buffer->GetLong(); $Buffer->Set(FRead($this->RconSocket, $PacketSize)); $Data = $Buffer->Get(); $Remaining = $PacketSize - StrLen($Data); while ($Remaining > 0) { $Data2 = FRead($this->RconSocket, $Remaining); $PacketSize = StrLen($Data2); if ($PacketSize === 0) { throw new InvalidPacketException('Read ' . strlen($Data) . ' bytes from socket, ' . $Remaining . ' remaining', InvalidPacketException::BUFFER_EMPTY); break; } $Data .= $Data2; $Remaining -= $PacketSize; } $Buffer->Set($Data); return $Buffer; }