I have a client who is looking to reduce the number of bytes transmitted over the wire to the absolute minimum. When creating a udpClient class and invoking the receive method, a byte array is returned. Currently I’m using receiveBytes.Length to get the number of bytes in the message.
However, under heavy load with multiple messages coming in, it’s been suggested that this is not sufficient, justifying the need to send the packet length as the first 2 bytes of the message.
Can I depend on either a complete packet or no packet being received, and hence rely on the Length property?
Edit
Thanks for all the comments.
Using UDP is in addition to TCP. TCP is used when we need to implement sequence and a guarantee. UDP will be used for data that is good to have in any order but not critical. Yes, I know it means adding OTT encryption. My question was simply can I depend on ONLY complete packets arriving.
Each UDP packet is delivered independently, and with no guarantee that any other packet will arrive.
How would you (on receiving one) know to wait for another one, and what could you do if it never turned up? Long way of saying, you’ll receive the sent message or none at all.