dreamz
11-06-2000, 12:30 PM
Hi,
I am writing a PHP4 script that is able to open a socket to a telnet server, and to send and receive messages.
PHP4 has some nice functions for this: fopensocket(), fgets(), fputs(). I used these functions to access an FTP server, and all went fine.
When I try to access a telnet server however, I receive garbage (non-ASCII). Is there something a telnet client must do before it can receive ACSII messages?
Here is a piece of the code that I use:
<code>
$fp = fsockopen($host, $port, &$errno, &$errstr, $timeout);
if($fp) {
[nbsp][nbsp]do {
[nbsp][nbsp][nbsp][nbsp]$response = fgets($fp,128);
[nbsp][nbsp][nbsp][nbsp]print $response;
[nbsp][nbsp]}
[nbsp][nbsp]while (!eregi('ogin',$response));
[nbsp][nbsp]fclose ($fp);
}
</code>
Wat happens is that the first fgets() results in something non-ASCII, and after the socket times-out.
Does anyone have an idea what is going on?
Kind regards,
Mark
I am writing a PHP4 script that is able to open a socket to a telnet server, and to send and receive messages.
PHP4 has some nice functions for this: fopensocket(), fgets(), fputs(). I used these functions to access an FTP server, and all went fine.
When I try to access a telnet server however, I receive garbage (non-ASCII). Is there something a telnet client must do before it can receive ACSII messages?
Here is a piece of the code that I use:
<code>
$fp = fsockopen($host, $port, &$errno, &$errstr, $timeout);
if($fp) {
[nbsp][nbsp]do {
[nbsp][nbsp][nbsp][nbsp]$response = fgets($fp,128);
[nbsp][nbsp][nbsp][nbsp]print $response;
[nbsp][nbsp]}
[nbsp][nbsp]while (!eregi('ogin',$response));
[nbsp][nbsp]fclose ($fp);
}
</code>
Wat happens is that the first fgets() results in something non-ASCII, and after the socket times-out.
Does anyone have an idea what is going on?
Kind regards,
Mark