I'm writing a simple telnet client library. I open sockets using fsockopen() and read and write to the socket using fgetc() and fwrite(). I use fgetc() instead of fread() to handle Telnet special commands and options like (IAC, ...).
the problem is that most of times I'm reading from the socket, it takes too long to return. as I have profiled it, it takes as long as the connection times out, and after that I have the results.
here are my reading method:
protected function getChar()
{
$char = fgetc( $this->_socket );
return $char;
} // public function getChar()
currently I use this condition to make sure stream is finished:
$char = $this->getChar();
if ( $char === false ) {
// end of the stream.
}
is there any other way to find out that the stream is finished an all data is read?
Udate: I think the EOF character in Telnet protocol is not what PHP expects as EOF, and that's why the script can not find end of the stream. does anyone know what is the EOF (end of file) character in Telnet protocol?