I am trying to send an image upload to a Qt server through a socket and render it on a client created using Java. So far, I have only passed strings for communication from both sides and tried different examples for sending images, but without any results.
The code I used to transfer the image to qt is:
QImage image; image.load("../punton.png"); qDebug()<<"Image loaded"; QByteArray ban;
At the other end, code for reading in Java:
BufferedInputStream in = new BufferedInputStream(socket.getInputStream(),1); File f = new File("C:\\Users\\CLOUDMOTO\\Desktop\\JAVA\\image.png"); System.out.println("Receiving..."); FileOutputStream fout = new FileOutputStream(f); byte[] by = new byte[1]; for(int len; (len = in.read(by)) > 0;){ fout.write(by, 0, len); System.out.println("Done!"); }
The process in Java gets stuck until I close the Qt server, and after that the created file is corrupted.
I will be grateful for any help, because it is necessary for me, and I am new to programming in both languages.
I also used the following commands, which now complete the receiving process and display a message, but the file is damaged.
socket->write(ban+"-1"); socket->close(); in qt.
And in java:
System.out.println(by); String received = new String(by, 0, by.length, "ISO8859_1"); System.out.println(received); System.out.println("Done!");
