Java NIO: What does IOException: Broken pipe mean? -


For some of my Java NIO connections, when I have a SocketChannel.write (ByteBuffer) Calls, it throws a IOException : "broke pipe".

What causes "broken pipes", and, more importantly, is it possible to get it from that position? If this can not be fixed, then it seems that it would be a good sign that an irreversible problem has occurred and I should close this socket connection. Is this a reasonable assumption? Is there ever a time when it happens IOException , while the socket connection is still properly connected in the first place (instead of failing at some point in some work)?

On one side note, it's wise to always call SocketChannel.isConnected () a SocketChannel.write () before attempting And if so, then I can also assume that the connection is "broken" and should be closed if both SocketChannel.isConnected () and SocketChannel.isConnectionPending () Both false ?

Thank you!

What causes "broken pipes", and more importantly Is it possible to recover from that state?

This is due to something close to the connection (this is not your application which has closed the connection: resulting in a different exception.)

It is not possible to recover connections. You have to open a new account.

If this can not be fixed, then it seems that it would be a good sign that an irreversible problem has occurred and I should close this socket connection. Is this a reasonable assumption?

Yes Once you receive this exception, the socket will never work again. Closing is the only wise thing to do.

There was ever a time when this IOException occurs while the socket connection is still being properly added in the first place (a functional connection which is some point But fail) instead?

No (or at least not, without destroying the OS'es network stack, JVM and / or the proper behavior of your application.)


It is always wise to call SocketChannel / socketchannel.write () ...

Before

< / P>

before calling RISax () before the call uses the external (external) resource r There is a small chance that the status of the resource between two calls will change.

In this particular case, Calling isconnected () is redundant. This method is defined to go back to true , if socket The last few points were attached . It does not tell you that the connection is still alive. The only way to determine whether the connection is still alive is to try to use it; Like reading or writing.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -