Hello. Suddenly ran into a problem. You need to transfer images one by one through the network. Images are generated and saved on the computer. Next, you need to transfer over the network. The receiver receives only 1 file, which grows to infinity, instead of taking each picture separately. Do not tell me where the error is.
Broadcast:
while(true){ BufferedOutputStream(soketOutStream); File file = new File (index + ".jpg"); FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int readed; while ((readed = fis.read(buf)) != -1) { baos.write(buf, 0, readed); } fis.close(); byte[] data = baos.toByteArray(); bisOutVideo.write(data, 0, data.length); bisOutVideo.flush(); bisOutVideo.close(); } Receiver:
int counti=0; bisIn = new BufferedInputStream(soketInputStream) while (true) { FileOutputStream file = new FileOutputStream(messagerInput+"/"+counti+".jpg"); byte[] b = new byte[1024]; int count = 0; while ((count = bisIn.read(b)) != -1) { file.write(b, 0, count); } file.close(); counti++; } Does not exit the loop, last indefinitely - while ((count = bisIn.read(b)) != -1)
while (true), in which there is not a singlebreak-a. These are the very real endless loops. - RegentsoketOutStream,soketInStream,bisOutVideo. This is necessary so that you can test and find the problem in the code. So far, I can say that permanent writing and reading withoutsleepin an infinite loop is not a sensible design and can ruin anything. - Regent