fsockopen()を使用して telnet システムと通信する方法についてのガイドを探しています.... 正常に接続されていますが、コマンドの送信に失敗しています。fwrite()
人々がいくつかのヘッダーを送信していることを示すドキュメントを見てきました。
現在、telnet サーバーに対して実行しているコマンドはversion
、$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);
}