We have an application that consists of three threads: one for the GUI, one that listens on a SocketConnection and one that every now and then sends messages out on the same SocketConnection.
The read thread calls read(buffer, offset, length) which I would expect to either return some data or block, as the connection is always open.
Instead the read never blocks. It either returns data or returns a -1 length. If I loop on the read statement then it will continue returning -1 until some more data arrives and will then return that. It is almost as if the -1 is saying there is no data available. Eventually after receiving a few messages it will then throw an exception as if it has lost the connection.
I have tried the same code using a single byte read() call and the behaviour is the same.
Can anyone see where I am going wrong here? Is it simply impossible to hold open a SocketConnection and receive messages on it every now and then? Could it be that sending messages on the same socket is somehow getting in the way of the reads?