Android: Image received over socket is corrupted

瘦欲@ 提交于 2019-12-02 13:38:55

You're combining buffered and unbuffered I/O on the same underlying streams. The buffered reader will steal data from the other stream by filling its buffer with whatever is available. You have data input and output streams: use them for everything. You can send the file size via writeInt()/readInt().

You have already one .read() before the while loop. And those bytes you do not write() so the client does not receive the first bytes of the file. O i see now that you write them but do not count them in size. Anyhow: bad construction. And for the first read you should have used a count variable too. And write only count bytes. Better remove the first read completely.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!