如何使用TIdTelnet发送命令? [英] How do I use TIdTelnet to send commands?

查看:655
本文介绍了如何使用TIdTelnet发送命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的程序中模拟Vidalia中的新身份按钮( Tor GUI)。 我问过这个,基于Rob Kennedy的答案,我在我的应用程序中尝试过:

I am trying to simulate the "new identity" button in Vidalia (the Tor GUI) from my program. I asked about that, based on Rob Kennedy's answer, I tried this in my application:

IdTelnet1.Host:='127.0.0.1';
IdTelnet1.Port:=9051;
IdTelnet1.Connect(-1);
IdTelnet1.SendCmd('SIGNAL NEWNYM');

但它对我来说没有效果。即使发送命令后,我也得到相同的代理。

But it has not worked for me. Even after I send the command, I get the same proxy.

我正在使用Indy 9。

I am using Indy 9.

不知道我不知道如何使用TIdTelnet或者不知道如何发送该特定命令。

I don't know whether I don't know how to use TIdTelnet or don't know how to send that specific command.

推荐答案

您不能使用TIdTelnet的SendCmd()方法。 TIdTelnet使用从套接字连续读取的内部读取线程(因为Telnet是可以随时接收数据的异步协议)。 SendCmd()执行自己的内部读取以接收发送的命令的响应。两个阅读操作相互干扰(同样的原因,这个问题也存在于Indy 10的TIdCmdTCPClient组件中)。

You cannot use the SendCmd() method with TIdTelnet. TIdTelnet uses an internal reading thread that continuously reads from the socket (since Telnet is an asynchronous protocol that can receive data at any time). SendCmd() does its own internal reading to receive the sent command's response. The two reading operations interfer with each other (this issue also exists in Indy 10's TIdCmdTCPClient component for the same reason).

要发送带有TIdTelnet的传出命令,必须使用它的SendCh()方法可以单独发送每个字符(如果升级到Indy 10,TIdTelnet有一个SendString()方法为您处理),然后等待OnDataAvailable事件根据需要处理响应。

To send an outgoing command with TIdTelnet, you must use its SendCh() method to send each character individually (if you upgrade to Indy 10, TIdTelnet has a SendString() method whch handles that for you) and then wait until the OnDataAvailable event to process the response as needed.

除非TOR实际上使用真正的Telnet协议(Telnet序列和全部),那么最好使用TIdTCPClient而不是TIdTelnet。 TIdTelnet是特定于Telnet的客户端,而不是像TIdTCPClient那样的通用TCP / IP客户端。

Unless TOR is actually using the real Telnet protocol (Telnet sequences and all), then you are better off using TIdTCPClient instead of TIdTelnet. TIdTelnet is a Telnet-specific client, not a general purpose TCP/IP client like TIdTCPClient is.

这篇关于如何使用TIdTelnet发送命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆