Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have an android app that talks to a program on a PC. I'm using the Android (Java) Socket class. If I stop and restart the PC app the next time I send something from Android I get an IO Exception "Broken Pipe". My question is not about that. Here's the question:

After getting the broken pipe exception if I query the Socket's isClosed() method it returns false (i.e., it's not closed), and if I query the Socket's isConnected() method it returns true, i.e., that it IS connected. Could someone please explain these results to me? Thanks in advance!

like image 274
user316117 Avatar asked Jun 05 '12 14:06

user316117


People also ask

How do you handle broken pipe exception?

The simple solution is not to shut the socket down before trying to send it data. This can also happen on pipes, but it doesn't sound like that's what you're experiencing, since it's a network server. You can also just apply the band-aid of catching the exception in some top-level handler in each thread.

What causes TCP broken pipe?

Share: The broken pipe is a TCP/IP error occurring when you write to a stream where the other end (the peer) has closed the underlying connection. The first write to the closed connection causes the peer to reply with an RST packet indicating that the connection should be terminated immediately.

What is a broken pipe error Java?

'Broken pipe' errors usually occur when the browser is closed before the request can be completed. They are harmless. There are various reasons, but the most common being a browser session being closed while the request is still processing.

What does error 32 broken pipe mean?

The broken pipe error usually occurs if your request is blocked or takes too long and after request-side timeout, it'll close the connection and then, when the respond-side (server) tries to write to the socket, it will throw a pipe broken error.


1 Answers

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?

like image 90
Ben Barden Avatar answered Sep 19 '22 05:09

Ben Barden