I am working on a network application written in Java using ObjectOutputStream and ObjectInputStream on top of Sockets for messaging. My code is as follows:
Sender:
ObjectOutputStream out; ObjectInputStream in; try{ Socket socket=new Socket(address, port); socket.setSoLinger(true, socketLingerTime); out=new ObjectOutputStream(socket.getOutputStream()); out.writeObject(message); out.flush(); out.close(); }catch (variousExceptions)...
Recipient:
Object incoming; try{ incoming=myObjectInputStream.readObject(); }catch (SocketException socketError) { if (socketError.getMessage().equals("Connection reset")) {
Sometimes the message goes through ok, but sometimes I get a thrown exception instead of an object. Shouldn't a flash push a message to the other side? Am I somehow using this function incorrectly? Or is it some kind of bug in the Java / OS core network code?
Thanks!
UPDATE:
I have tracked this several times already, and it seems that this happens only when system resources are credited to something. I could not reproduce it outside of VirtualBox, but it could be just because VirtualBox does not have many resources to start with. I will keep this question up to date as I study it further.
user597474
source share