How to Use TELNET

PHPoC can be set as a TELNET server by using "set api telnet" command. The following is an example of a TELNET server.

example of a TELNET server

$port = 23;                             // port number
$pid = pid_open("/mmap/tcp0");          // open TCP 0
pid_ioctl($pid, "set api telnet");      // set api to TELNET
pid_bind($pid, "", $port);              // binding
pid_listen($pid);                       // listen TCP connection
    $state = pid_ioctl($pid, "get state");
while(($state != TCP_CLOSED) && ($state != TCP_CONNECTED));

if($state == TCP_CONNECTED)
    pid_send($pid, "Welcome to PHPoC TELNET server\r\n");
    echo "Connection has been established!\r\n";
    pid_close($pid);                    // close TCP connection


In the example above, PHPoC listens TELNET connection from clients. After connection is established, it prints a welcome message and close the connection.

※ If you want to test this example, open a TELNET client program on PC such as Tera Term and try connecting to PHPoC TELNET server.

※ If you want to do authentication including user identification, you should implement it in user script.