function waitMessage() { if (!$this->ConSock) { debug(sprintf("Socket is not valid\n")); return false; } $size = 0; $val = fread($this->ConSock, 1); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } $size = ord($val) << 24; $val = fread($this->ConSock, 1); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } $size = ord($val) << 16; $val = fread($this->ConSock, 1); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } $size += ord($val) << 8; $val = fread($this->ConSock, 1); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } $size += ord($val); debug(sprintf("receive packet size '%d'<br>\n", $size)); $fake = fread($this->ConSock, 5); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } $size -= 5; // remove the fake $Buffer = ""; while ($size > 0 && strlen($Buffer) != $size) { $Buffer .= fread($this->ConSock, $size - strlen($Buffer)); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } } $msgin = new CMemStream(); $msgin->setBuffer($Buffer); // decode msg name $msgin->serialString($name); debug(sprintf("Message name = '%s'<BR>", $name)); $message = new CMessage(); $message->setBuffer(substr($msgin->Buffer, $msgin->Pos)); $message->setName($name); debug(sprintf("In message name = '%s'<br>", $message->MsgName)); return $message; }