Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TIdTelnet: How can I send HEX values between 128-255?


This question is answered.


Permlink Replies: 1 - Last Post: Dec 10, 2016 2:36 PM Last Post By: Remy Lebeau (Te...
Tyrone Nason

Posts: 1
Registered: 3/20/10
TIdTelnet: How can I send HEX values between 128-255?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 10, 2016 4:27 AM
I am trying the following code, [Indy10 Version: 10.6.2.0 - 10/12/2016] Delphi 7

IdTelnet1.Connect;
S := #$04 + #$03 + #$00 + #$00 + #$00 + #$0B + #$00 + #$00 + #$00 + #$65 + #$80;
IdTelnet1.SendString(S);

I have tried ,

IdTelnet1.IOHandler.DefStringEncoding := IndyTextEncoding_8Bit;
or
IdTelnet1.IOHandler.DefStringEncoding := Indy8BitEncoding;
or
IdTelnet1.IOHandler.DefStringEncoding := en8Bit;

But the result remains,

04 03 00 00 00 0B 00 00 65 3F


Tyrone
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TIdTelnet: How can I send HEX values between 128-255?
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 10, 2016 2:36 PM   in response to: Tyrone Nason in response to: Tyrone Nason
Tyrone wrote:

S := #$04 + #$03 + #$00 + #$00 + #$00 + #$0B + #$00 +
#$00 + #$00 + #$65 + #$80;

The last character is outside of the ASCII range, so it is subject to potential
data loss during charset conversions. The other characters are within the
ASCII range, and thus are not subject to data loss during most charset conversions.

IdTelnet1.SendString(S);

SendString() loops through the String passing each Char individually to the
TIdIOHandler.Write(Char) method. Since you are using a pre-Unicode version
of Delphi, the IOHandler first uses its DefAnsiEncoding property (which does
not exist in Unicode versions) to convert the Char data to Unicode, before
then using its DefStringEncoding property to encode the Unicode data as bytes
for transmission. Setting the DefStringEncoding to Indy's 8bit encoding
is fine, but you will have to do the same with the DefAnsiString property
as well:

IdTelnet1.IOHandler.DefAnsiEncoding := IndyTextEncoding_8Bit;
IdTelnet1.IOHandler.DefStringEncoding := IndyTextEncoding_8Bit;


With that in place, your AnsiString values will then get transmitted as-is.

If you do not set the DefAnsiEncoding property, the OS default Ansi charset
will be used instead. So, in your case, #$80 gets interpretted by the OS
charset as a Unicode character such as U+20AC, which is outside of the range
of characters that Indy's 8bit encoding allows (U+0000 - U+00FF), which is
why it gets encoded as $3F instead of $80. Removing the OS charset from
the picture fixes that.

The alternative is to use TIOHandler.Write(Byte) or TIOHandler.Write(TIdBytes)
directly, instead of using TIdTelnet.SendString(). The catch is that you
will have to handle CR bytes manually. If SendString() knows it is communicating
with an actual Telnet server (see the IAmTelnet property), it encodes CR
as CRLF. You would have to do the same if you need to send any CR bytes.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02