0

I am transferring image file from server socket to client socket while writing byte on outstream is i do close out stream after writing whole byte data on stream then it work fine but close the socket So from preventing socket close problem i am not closing the out stream from server side and then while loop is running infinite on client side while reading from inputstream.

Sending file from server side code below

  byte buf[] = new byte[1024];
    int len;
    try {
        while ((len = inputStream.read(buf)) != -1) {
            out.write(buf, 0, len);
        }

        out.flush();
  //            out.close();
        inputStream.close();
    } catch (IOException e) {
        Log.d(TAG, e.toString());
        return false;
    }

client side code reading data

byte buf[] = new byte[1024];
    int len;
    try {
        Log.e(TAG, "Size of image on client side" + inputStream.readInt());
        while ((len = inputStream.read(buf)) != -1) {
            Log.e(TAG, buf + "");
            out.write(buf, 0, len);
        }
    } catch (IOException e) {
        Log.d(TAG, e.toString());
        return false;
    }

So should i use any delimiter to stop while loop because what i understood is that if i don't close outstream from server so while doesn't meet with condition of -1 .

So any one help would be appreciated.

Nikhil Sharma
  • 593
  • 7
  • 23

0 Answers0