我正在尝试创建这样的东西:
telnet towel.blinkenlights.nl 666
您必须在终端中编写它并向您发送一些响应,如果服务器要求,用户也可以发送输入。
我已经搜索了很多,但没有得到足够的。只是这个小代码:
<?php
$IP_ADDR='127.0.0.1';
$PORT='80';
echo "Welcome to LOCALHOST...";
$connection = fsockopen($IP_ADDR, $PORT);
if(!$connection){
echo "No Connection";
}else{
echo "Hello, what's your name?";
}
?>
但输出显示如下:
telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
因此,在与 localhost 连接后,它没有显示输出,我必须输入任何字符,然后按 Enter,然后它会显示以下输出:
g
Welcome to LOCALHOST...Hello, what's your name?Connection closed by foreign host.
那么我怎样才能避免每次插入 char 输出呢?
请帮我。谢谢
编辑代码:
My Code :
$IP_ADDR='127.0.0.1';
$PORT='80';
$connection = fsockopen($IP_ADDR, $PORT);
if(!$connection){
echo "No Connection";
}else{
$filename = "sampledata.txt";
$somecontent = "Weekend is about to come.";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file";
exit;
}
echo "Success";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
}
Output :
telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
d
Success, wrote (Weekend is about to come.) to file (sampledata.txt)Connection closed by foreign host.