What, exactly, does a "broken pipe" exception mean to the Socket?

I got same problem when I was trying to send data from my Android App to a bluetooth module attached to an Arduino, and it it took me too long until I changed the bluetooth module with a new one and everything start working perfectly, so it is also worth checking your hardware, specially if you are confident about your code and running out of solutions.


Broken pipe means pretty much exactly what you're talking about here. The program on your side still has its socket wide open, but the socket on the other side is no longer in communication, and didn't go through the standard "close pipe" procedure. This can happen if the other side lost power suddenly, if the physical line was severed, or whatever. As such, locally the socket is registering as both open and connected - it's just connected to a broken pipe. Did you wish some practical advice here, or just the theory?


Socket.isClosed() and Socket.isConnected() only tell you what you have done to the socket. They aren't there to tell you anything about the state of the connection. You haven't closed the socket: it's open. You connected the socket: it's connected.

When you get any IOException operating a Socket other than SocketTimeoutException you must close the socket.