0

I have a function:

...
socket.getOutputStream().write("something".getBytes());
socket.getOutputStream().flush();
...

Works fine. Keep socket open. Trying to call this function again but get the error: java.net.SocketException: Broken pipe

despite the fact that

socket.isClosed - false
socket.isOutputShutdown - false
socket.isConnected - true

2
  • timeout connection are detected only when new data is written... checking isClosed() before write do not work. Commented Apr 15, 2011 at 6:46
  • I was unable to reproduce this via local Socket and ServerSocket test. There is something in your particular case, could you please provide more info? Commented Apr 15, 2011 at 6:54

2 Answers 2

3

It is most likely the other end has closed the connection. It is possible the first write failed as well, as write() does not guarenteed delivery. You only get an Exception once it knows the other end is not listening.

isClosed means; have I closed the connection

isOutputShutdown means; have I shutdown the output

isConnected means; has it ever connected

The only way to detect that a connection is truly up is to get a response from the other end telling you it has received your data. e.g. a response to a heartbeat. Without that response (which must be part of your protocol) you cannot be sure the other end has received it.

Sign up to request clarification or add additional context in comments.

Comments

0

Broken pipe means that you wrote data to a connection that had already been closed by the other end. This can indicate an application protocol error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.