I have a TCP client server, where client sends image to the server. Server receives it and manipulates the image. Then the server sends back that manipulated image to the client. Once the client receives that image, it will send next image to the server to be processed. This process continues till 100 images to be processed. How to implement it in Javathread any suggestions?
Issues: Client sends a file, server could not receive exactly same size of image file. Another issue is that server could not send back the modified file to server.
Flow should be like this a) client sends image b) server receives that image 3) then server starts to modify that image 4) server then send back that modified file to the client 5) client receives that modified file 5) client sends another image fine and procedure continue....Please help.
Now that I look at your code a bit more, there are several other problems.
First you haven't addressed the problem that the server doesn't know how big the file sent from the client is going to be. Looking at the size of a file on the server isn't going to work -- unless you're guaranteed that these files going back and forth are all going to be exactly the same size. It would be better to have the client send the file size first, before sending the file.
And even if you did know the size of the file, your code doesn't read the data sent from the client correctly. You're assuming that the "read(byte data, int offset, int size)" method reads the entire file. That isn't the case -- it might only read part of it. The method returns the actual number of bytes it read, but you're ignoring that. You should write a loop which keeps reading until the whole file is received. Or you might want to look into the java.nio.file.Files methods "copy(InputStream, Path, CopyOption...)" and "copy(Path, OutputStream)" to take care of that bookkeeping for you.
Many thanks. File size is always same in this case. I fixed the issues of read(byte data) using loop. After sending image to the server (port 1234), client should wait till it starts to receive the modified image from the server. How to manage it. Should client use sleep, e.g., Thread.sleep(1000) or use different socket for sending image and receiving modified image. I am stuck in this step. Please suggest.