Beginner OpenCV issue

also be aware, that real life [udp|tcp] packets will be fragmented
(by any device in your way)

while you can send a 10 mb buffer with a single call, you have to retrieve the output in a loop, assembling much smaller buffers (like 1k) until you have read the final bytecount

you never told us, what went wrong with our original, PIL based effort, but i guess, this is the problem