I have a UDP server reading images, both UDP and TCP. The protocol format is: length ID payload
When I try to read the payload or image itself, I can do it by using a FLAG, but this is not desirable. How can I stop reading the file in UDP (or know when there is no more data) and write into a file? The commented code, but using a FLAG, I dont want to use a FLAG as other clients may connect and will just transfer the raw image file.
Thanks
while (true) {
socket.receive(receivePacket);
/*
if (receivePacket.getLength() <= 8) {
cmd = new String(receivePacket.getData(), 0,receivePacket.getLength());
if (cmd.equals("END_FILE")) {
System.out.println("UDP ServerThread() Command: " + cmd);
break;
}
}*/
fos.write(receivePacket.getData(), 0, receivePacket.getLength());
}