Quote Originally Posted by Neverbirth
Your code is rather similar to what I already do, with just some slight differences . For example instead of global variables I use static ones as already pointed out, and I don't use two different byte arrays for the data treatment.
In your original post you stated
Currently I use a static byte array (static because some of the messages are rather large and arrive in several packages), and once I know I've received the whole message I use copymemory with a UDT, and treat it...
but, from the few lines that you posted, it appears that you always receive the incoming data into the static byte array, copy it to the UDT and then clear it. It isn't clear that you are preserving the data until all of it has arrived.

I used a global byte array because the entire UDT does not arrive in one piece. The other byte array was used for the .GetData and then I used copyPtr to move the receiving byte array to the appropriate position in the final byte array. I don't recall why I used a global for the initial receive.