clamum
Lifer
I'm transmitting a file via UDP from one host to another. The amount of data from the file that is being packaged in a UDP datagram is controllable by user input; right now I'm testing it with a 100 byte payload. The other host receives the data and appends it to a file on it's machine.
The problem is that I have to create a new byte array to store the data received BEFORE I can check how much data is carried by the datagram (i.e., you have to create a DatagramPacket before you can call the DatagramPacket's getData() method). Now, normally the data will be 100 bytes, but if the filesize of the file isn't divisible by 100, then the last chunk of data will be less than 100 bytes, but stored in an array of size 100. Thus, then I go to append the last chunk of data to the file, it will be larger than it should be.
Does anyone have any suggestions on how I could go about solving this problem? Thanks!
EDIT: I fixed it, there's a method in the DatagramPacket (getLength) that actually checks the amount of data transferred, not just the array size. That solved it.
The problem is that I have to create a new byte array to store the data received BEFORE I can check how much data is carried by the datagram (i.e., you have to create a DatagramPacket before you can call the DatagramPacket's getData() method). Now, normally the data will be 100 bytes, but if the filesize of the file isn't divisible by 100, then the last chunk of data will be less than 100 bytes, but stored in an array of size 100. Thus, then I go to append the last chunk of data to the file, it will be larger than it should be.
Does anyone have any suggestions on how I could go about solving this problem? Thanks!
EDIT: I fixed it, there's a method in the DatagramPacket (getLength) that actually checks the amount of data transferred, not just the array size. That solved it.