我正在寻找有关如何使用fsockopen()与telnet系统进行通信的指南....我连接得很好,但命令无法发送。我看过一些文档fwrite()
,显示人们发送了一些标题。
目前,我通过version
运行针对telnet服务器的命令$class->send("version");
。我是否需要发送标题或其他内容以便telnet服务器获取命令,或者我可以发送它吗?
/**
* Connect to the GMC telnet system
*/
public function connect () {
$this->connection = fsockopen($this->socket['host'], $this->socket['port'], $errorNumber, $errorMessage, 30);
if (!$this->connection) {
$this->error = 'Unable to connect to GMC: '.$errorMessage.' ('.$errorNumber.')';
return false;
}
stream_set_timeout($this->connection, $this->commandTimeout);
return true;
}
/**
* Send a command to GMC
*/
public function send ($command) {
//write to socket
if (fwrite($this->connection, $command) === false) {
$this->error = 'Unable to write to socket';
return false;
}
sleep(1);
//read socket
if (($response = fgets($this->connection)) === false) {
$this->error = 'Unable to write to socket';
return false;
}
return $response;
}
/**
* Disconnects from the GMC telnet system
*/
public function disconnect () {
return fclose($this->connection);
}
答案 0 :(得分:0)
显然我需要做的就是确保在命令结束时加入\n
!!