Solved

Copying a binary buffer to a TIdBytes object

Posted on 2013-01-28
3
1,224 Views
Last Modified: 2013-02-03
I am using Indy10 with C++ builder XE2 and I want to send a packet of binary data using a UDPServer control. I have a plain buffer of data to send in an array of unsigned chars.
Can someone explain how to move data from a plain character array to a TIdBytes object

The code is as follows :

unsigned char buff[566];
TIdBytes ABuffer;

SetupBuffer(buff) // data is prepared for sending (566 bytes)

// .....  some code needed to move the buffer into the TIdBytes buffer ??

// now send the data using UDP to a remote host listening on port 10036

IdUDPServer1->SendBuffer(remotehost,10036,ABuffer);

Thanks,

Roger
0
Comment
Question by:alcindor
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 38827408
That could be

unsigned char buff[566];
TIdBytes ABuffer;

ABuffer.Length = 256;

for (int i = 0; i < 256; ++i)
  ABuffer[i] = buff[i];

Open in new window


But IMHO it might be easier to pass ABuffer to 'SetupBuffer()' instead.
0
 
LVL 2

Accepted Solution

by:
alcindor earned 0 total points
ID: 38830557
I have found the answer:

ABuffer.set_length(sizeof(buff));
ABuffer =  RawToBytes(buff, sizeof(buff));
0
 
LVL 2

Author Closing Comment

by:alcindor
ID: 38848251
I found the solution myself
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now