Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: CBXE8 - TIdUDPClient - How to send raw ASCII bytes ?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: May 4, 2015 11:03 PM Last Post By: GAI CHEW KAI
GAI CHEW KAI

Posts: 117
Registered: 7/25/14
CBXE8 - TIdUDPClient - How to send raw ASCII bytes ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 30, 2015 12:51 AM
Embarcadero® C++Builder XE8 Version 22.0.19027.8951 and Indy 10.

QUESTIONS:

1. How to send raw bytes by using TIdUDPClient->Send() if the 10 bytes data to send is like below ?

0x01 0xAE 0x00 0x00 0x00 0x00 0x73 0xE3 0x00 0x03

2. How to convert the above data stream to string if TIdUDPClient->Send( string ) and how many bytes actually it is sending out ?

Please advise.

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: CBXE8 - TIdUDPClient - How to send raw ASCII bytes ? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 30, 2015 9:36 AM   in response to: GAI CHEW KAI in response to: GAI CHEW KAI
GAI wrote:

How to send raw bytes by using TIdUDPClient->Send()

Send() sends an encoded UnicodeString. To send raw bytes instead, use SendBuffer(),
eg:

TIdBytes data;
// populate data as needed...
IdUDPClient1->SendBuffer(host, port, data);


Or:

TIdBytes data;
// populate data as needed...
IdUDPClient1->Host = host;
IdUDPClient1->Port = port;
IdUDPClient1->SendBuffer(data);


To populate the TIdBytes, you can do this:

data.Length = 10;
data[0] = 0x01;
data[1] = 0xAE;
//...
data[9] = 0x03;


Or this:

data.Length = 10;
memcpy(&data[0], "\x01\xAE\x00\x00\x00\x00\x73\xE3\x00\x03", 10);


Or this:

data = RawToBytes("\x01\xAE\x00\x00\x00\x00\x73\xE3\x00\x03", 10);


--
Remy Lebeau (TeamB)
GAI CHEW KAI

Posts: 117
Registered: 7/25/14
Re: CBXE8 - TIdUDPClient - How to send raw ASCII bytes ? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 4, 2015 11:03 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks again, is working now.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02