views:

97

answers:

1

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.

+7  A: 

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.

Remy Lebeau - TeamB
I based my answer off [an example](http://ubuntuforums.org/showthread.php?t=558051) showing how to use the Unix telnet command to connect to Tor. I concluded that telnet is the right protocol for the job.
Rob Kennedy
A telnet client is often used for testing text-based protocols, but mainly only because it is readily available in most OS installs. However, Telnet is a protocol all of its own, with its own semantics, and Indy's implementation of TIdTelnet plays to that, and thus does not make a good general-purpose protocol client. Use TIdTCPClient directly for that, eg: `Client.Connect; Client.SendCmd('AUTHENTICATE ...', 250); Client.SendCmd('signal NEWNYM', 250'); Client.Write('quit'); Client.Disconnect;`
Remy Lebeau - TeamB