0

I have a Client-Server app, sending Data from an Android Phone, to a Tablet - Phone calls, SMS, Battery condition etc. The Phone is the Client, the Tablet the Server, and both run Services, with Partial WakeLocks to keep them alive for long enough, plus the Client has a PhoneStateListener, and a BroadcastReceiver to keep track of calls, Battery condition etc.

The point is that both ends stay alive, but at some stage - according to my logging set-up about 20 minutes - the Client reports that I have a "Broken Pipe".

On the Server side, I have a blocking Server, in a loop, listening for single byte commands from the Client, within a Thread, but I also added a Thread that runs once every minute find out what is causing the problem.

As the Client detects a broken pipe, I am assuming that there is a condition that the Server socket is in, that causes it, but I am testing the following -

  • Whether the Socket is open or not.
  • Whether the Input or Output Stream is open,
  • Whether any of them are null.

Unfortunately, all of these conditions are fine, and it is as though the
connection is still active. What should I be looking for ?

What I want to be able to do is once the Client detects the "Broken Pipe", the Server does too, and attempts to re-connect.

Douglas Brett
  • 171
  • 3
  • 8

1 Answers1

0

'Broken pipe' means that you have written to a connection that had already been closed by the other end. Sometimes it shows up in a write and sometimes in a read. In all cases it refers to a prior write.

In your case the client gets this error, ergo the server has closed the socket. Your observations notwithstanding. Possibly you aren't aware that closing the input or output stream closes the socket.

Re your last paragraph, the server has already closed the socket, so it can't detect that the client gets an error, but it doesn't matter, as it has no socket to take corrective action with anyway. All the client has to do is reconnect. The server cannot possibly reconnect.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Thanks for the reply. The Server is not intentionally closing down the socket, I have read somewhere that Socket connections can be lost after a time, due to sleeping for a time - maybe the fact that is a blocking server ? It is currently a while loop, I might change to a non-blocking set-up, and a Timer & TimerTask set-up instead. The thing that I don't understand is that the "Supervisor Thread" I have running in the Server Service is unable to detect any changes in the condition of the Socket, yet it detects when it is closed, when the service is intentionally shut down. – Douglas Brett May 30 '14 at 22:53