2

In my software i need to send messages between client and server through an ObjectOutputStream.

The core of the sender method is the following:

....

try {
    objWriter.writeUnshared(bean);
    objWriter.flush();
} catch (Exception e) {
    ....
}

...

Running my application on windows XP when the network cable is removed the writeUnsahred throw me an exception.

Now i'm trying to run my application into ubuntu 12.10 and the method don't throw anything if i remove the cable!

Any hint??

Matteo Gatto
  • 616
  • 11
  • 28

2 Answers2

1

Whether and when you get the exception depends on:

  • how large the socket send buffer is at your end
  • how large the socket receive buffer is at the peer
  • how much unacknowledged data you have already written
  • how long it is since you wrote that, and
  • the internal timers of your TCP stack.

The only part of that you can control from Java is your own socket send buffer. It is therefore entirely unpredictable when and if the exception will be delivered. You therefore must not write your application to depend on a specific behaviour.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

Yes but following the methods called by writeUnshared and flush i see that write(OutputStream.class:106) is called and this method must generate an exception if the stream is closed... So i use that information to check if my channel is active.. the problem is that in ubuntu the channel seems to be open even if i remove the cable..

Matteo Gatto
  • 616
  • 11
  • 28