public function wait($quantity = 0)
{
$count = 0;
$info = stream_get_meta_data($this->streamSocket);
while (is_resource($this->streamSocket) && !feof($this->streamSocket) && !$info['timed_out']) {
$line = $this->receive();
if ($line === false) {
return null;
}
if (strpos($line, 'PING') === 0) {
$this->handlePING();
}
if (strpos($line, 'MSG') === 0) {
$count = $count + 1;
$this->handleMSG($line);
if ($quantity != 0 && $count >= $quantity) {
return $this;
}
}
$info = stream_get_meta_data($this->streamSocket);
}
$this->close();
return $this;
}