How to suppress echo with TIdTelnet?

Using Indy10 - DelphiXE. How do I tell the telnet server I'm connecting to with TIdTelnet so as not to respond to the commands I send to the telnet server?

This is my current attempt (which does not work), I am trying to send the IAC DO SUPPRESS_LOCAL_ECHO sequence to each telnet entry, but I believe this should be done at the negotiation stage?

 uses TIdTelnet, ... procedure TIOTelnetConnection.SendSupressEcho; var Resp: TIdBytes; begin SetLength(Resp, 3); Resp[0] := TNC_IAC; Resp[1] := TNC_DO; Resp[2] := TNO_SUPLOCALECHO; FIOConnection.IOHandler.Write(Resp); end; procedure TIOTelnetConnection.Write(Str: AnsiString); begin SendSupressEcho; if Str <> '' then FIOConnection.IOHandler.Write(Str); end; 

looking at the source of TIdTelnet , I see the Negotiate procedure, but it is protected, how can I redefine its behavior?

+4
source share
3 answers

If the server sends you an IAC WILL ECHO , TIdTelnet hard-coded to send an IAC DO ECHO response, and then fires the OnTelnetCommand(tncNoLocalEcho) event to tell you not to send what you send locally.

If the server sends you an IAC WONT ECHO , TIdTelnet hard-coded to send an IAC DONT ECHO response, and then fires the OnTelnetCommand(tncLocalEcho) event to tell you locally the echo that you are sending.

If the server sends you IAC DO ECHO , TIdTelnet hard-coded to send an IAC WILL ECHO response, and then fires the OnTelnetCommand(tncEcho) event so that you can respond to everything you receive.

If the server sends you an IAC DONT ECHO , TIdTelnet hard-coded to send an IAC WONT ECHO response, and then fires the OnTelnetCommand(tncLocalEcho) event so that you can respond to everything you receive.

So, if you do not want the server to return to you, you can send the IAC DONT ECHO command to the server, and not the IAC DO SUPLOCALECHO . The server will then respond with either IAC WONT ECHO or IAC WILL ECHO (which is likely to be TIdTelnet , then will respond, but the server will not respond again because its current ECHO state does not change, avoiding an infinite loop of response).

+5
source

@Remy Lebeau: As I understand it, you say: If the server sends you IAC DO ECHO, TIdTelnet is hard-coded to send an IAC WILL ECHO response, and then fires the OnTelnetCommand ( tncEcho ) event so that you can respond to everything you get.

This makes sense and is consistent with what RFC857 offers ...

However, the code has:

 procedure TIdTelnet.Negotiate; ... TNC_DONT: begin b := IOHandler.ReadByte; case b of TNO_ECHO: begin DoTelnetCommand(tncEcho); //DoStatus('ECHO'); {Do not Localize} Reply := TNC_WONT; end; else Reply := TNC_WONT; end; 

and

  TNC_DO: begin b := IOHandler.ReadByte; case b of TNO_ECHO: begin Reply := TNC_WILL; DoTelnetCommand(tncLocalEcho); end; 

Is this code wrong? (in version 10.6.0.497 from Indy)

I believe this makes sense:

  procedure TIdTelnet.Negotiate; ... TNC_DONT: begin b := IOHandler.ReadByte; case b of TNO_ECHO: begin // Agree not to echo back everything received from server // (This being the default - you shouldn't echo unless asked to) Reply := TNC_WONT; // Therefore only print locally what is sent to server // (Again: this is the default behavior without negotiation) DoTelnetCommand(tncLocalEcho); end; else Reply := TNC_WONT; end; 

and

  TNC_DO: begin b := IOHandler.ReadByte; case b of TNO_ECHO: begin // Agree to echo back everything received from server Reply := TNC_WILL; DoTelnetCommand(tncEcho); // Therefore you may still have to locally print what you send // (ie local echo is usually still implicit in this) end; 

In other words, I believe that the code is currently replaced with what it should be - that the server sending DO ECHO should create the tncEcho token - this is what you said in the above quote!

How did this mistake survive for so long? (probably because most Telnet servers no longer bother with RFC857 echo matching)

Unfortunately, the only way I can β€œcompensate” for this error at the moment is to create a copy of the IDTelnet.pas file; associate this with your project in the Project Manager; and then make corrections to this copy as described above.

0
source

To solve the original question: β€œHow to suppress an echo using TIdTelnet?”, I would suggest the following steps:

  • Add a TIdConnectionIntercept to your form and connect it to your TIdTelnet Component through the Intercept property using the Inspector object.

  • Create an event handler for the TIdConnectionIntercept OnSend event.

  • Use this to determine when its var ABuffer: the TIdBytes parameter receives a response to the server negotiation command with respect to the echo. Note that the buffer will EXACTLY and ONLY all three bytes of the response due to how the response is filled and sent to TIdTelnet.Negotiate

  • Change the middle byte as desired (i.e. force change from WILL to WONT or DO DONT according to what you are trying to provide).

The good-un quest

Remember, of course, that this method introduces a change caused by AFTER TidTelnet OnTelnetCommand being called, so you will need to change everything that you configured in this handler to set your modified response.

0
source

Source: https://habr.com/ru/post/1487303/


All Articles