PDA

View Full Version : Opening a socket to telnet server


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, &amp;$errno, &amp;$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

Aaron O'Neil
11-06-2000, 10:39 PM
Telnet isn't just a plain-text connection. There is some negotiation expected when you connect to a telnet server. If you want the details of it, you can read the Telnet RFCs (easy to find, go to yahoo and search for &quot;telnet rfc&quot;).

Aaron