如何使用TIdTelnet发送命令?
我正在尝试从我的程序模拟 Vidalia 中的“新身份”按钮(Tor GUI)。 我问过这个,根据罗布·肯尼迪的回答,我在我的申请中尝试了这个:
IdTelnet1.Host:='127.0.0.1';
IdTelnet1.Port:=9051;
IdTelnet1.Connect(-1);
IdTelnet1.SendCmd('SIGNAL NEWNYM');
但它对我不起作用。即使在发送命令后,我也会得到相同的代理。
我正在使用 Indy 9。
我不知道我是否不知道如何使用 TIdTelnet 或者不知道如何发送该特定命令。
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.
I am using Indy 9.
I don't know whether I don't know how to use TIdTelnet or don't know how to send that specific command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能将 SendCmd() 方法与 TIdTelnet 一起使用。 TIdTelnet 使用内部读取线程,不断从套接字读取(因为 Telnet 是异步协议,可以随时接收数据)。 SendCmd() 执行其自己的内部读取以接收发送命令的响应。两个读取操作互相干扰(出于同样的原因,Indy 10 的 TIdCmdTCPClient 组件中也存在此问题)。
要使用 TIdTelnet 发送传出命令,您必须使用其 SendCh() 方法单独发送每个字符(如果您升级到 Indy 10,TIdTelnet 有一个 SendString() 方法为您处理该命令),然后等待 OnDataAvailable 事件根据需要处理响应。
除非 TOR 实际上使用真正的 Telnet 协议(Telnet 序列等),否则最好使用 TIdTCPClient 而不是 TIdTelnet。 TIdTelnet 是特定于 Telnet 的客户端,而不是像 TIdTCPClient 那样的通用 TCP/IP 客户端。
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).
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.
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.