Search code examples
phpsocketstcptelnet

PHP Telnet connection message


When connecting from terminal to remote device I get:

Trying XX.XX.XX.XX...
Connected to XX.XX.XX.XX.
Escape character is '^]'.


User Name:

But when connecting via PHP and reading data using socket_read function

I get:

��������


User Name:

Here's how my connect and read code looks:

$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

$buffer = @socket_read($this->socket, $this->length);

Why I'm not getting regulat text when connecting from php?


Solution

  • That is because what output you get above is not from the server but from the telnet verbose. So technically it has no role with the socket communication stack but a simple message for users on how to use telnet. On the other hand what you did in PHP is socket programing, so you will only see what comes after the telnet greetings message

    As far as those characters in beginning go , have a look at RFC