Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split and join array in C++ for UDP?

Tags:

c++

udp

I have a byte array like this:

lzo_bytep out; // my byte array
size_t uncompressedImageSize = 921600;

out = (lzo_bytep) malloc((uncompressedImageSize + 
          uncompressedImageSize / 16 + 64 + 3));
wrkmem = (lzo_voidp) malloc(LZO1X_1_MEM_COMPRESS);

// Now the byte array has 802270 bytes
r = lzo1x_1_compress(imageData, uncompressedImageSize,
        out, &out_len, wrkmem);

How can I split it into smaller parts under 65,535 bytes (the byte array is one large image which I want to sent over UDP which has upper limit 65,535 bytes) and then join those small chunks back into a continuous array?

like image 311
Richard Knop Avatar asked Dec 28 '10 20:12

Richard Knop


1 Answers

The problem with doing this is that the UDP packets can arrive out or order, or be dropped. Use TCP for this; that's what it's for.

like image 84
Billy ONeal Avatar answered Sep 23 '22 02:09

Billy ONeal