PHP: socket_read returning only part of response (telnet)
My router has an API, where you can connect via Telnet and among other
things control an Tellstick. I'm connecting to the router using PHP. I can
execute commands, but when I'm trying to read the response using
socket_read, I only get part of it.
This is what it looks like when connected to the router using Windows'
telnet function: http://i.imgur.com/hnIrVQa.png. The response to the
command ts aliases is several lines long.
When I try to get that response via my PHP script, I just get the first
line, ALIAS=´Hallway´.
The code I'm using to listen looks like this:
function reply($insocket) {
if (false !== ($bytes = socket_read($insocket, 2048, PHP_BINARY_READ))) {
return " Reply: <code>$bytes</code> \n<br>";
} else {
return "socket_read() failed; reason: " .
socket_strerror(socket_last_error($insocket)) . "\n";
}
/*
while ($out = socket_read($insocket, 2048)) {
return $out;
}
*/
}
All of the code: http://codepad.org/jykGgivv
No comments:
Post a Comment