We have created a socket in a multithreaded JAVA application on Windows, which has to read data in sequential form. But we are facing issue in reading the data from the inputstream
For example , data order is
1-100 (1,2,3,4,...100)
101-200
201-200
and so on..
We are able to read from 1-100 in proper sequential manner, but not able to read next set of data, i.e. 101-200. But can read further set of data properly.
The data is coming at our end properly (as seen in etheral log’s), but stream is not able to read it.
Here is the code snippet
socket.getInputStream.read(buffer);
socket is of Socket class type.
What can be the possible reason behind the same? Please share your views.
No it isn’t. That snippet doesn’t compile. And the correct snippet is trivially obvious.
The only ways that can miss data are (i) if another thread is reading the socket at the same time, or (ii) if you are using BufferedInputStream or BufferedReader at one time and not at another.