I'm making an Android app for playing online radio. I'm using Java Socket for connection and it's InputStream to read stream data. Actually there is HTTP request and response without length with content type such as audio/mpeg.
All works fine until bandwidth becomes low (using mobile internet or connected to slow/very remote server) - InputStream may return EOF (-1) at arbitrary time.
Please could you explain the nature of such behavior and possible ways to deal with it. I set read timeout (Socket.setSoTimeout), so why it doesn't throw timeout exception if the case is low bandwidth? Maybe there are another socket options that may help?
That happens when you have Client connected and then It disconnects and you are trying to read from it. I handle this asking the length of the message, If it is negative, I restart the connection.
E.G.