Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

readObject causing error

 
Dave Butterwick
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am experimenting with writing/reading objects over sockets. When I set up both the server (who listens for a connection) and a client(who initiates a connection) on the same machine the server accepts the connection, gets the input stream and eventually the objectinputstream from the newly formed socket and the readObject method on the ObjectInoutStream on the server side reads the sent object without a problem. But when I have the server and the client running on different machines this process works a few times then I get a error on the readObject() method that indicates an unknown source and the connection gets reset and never works again.

I started just sending a String object across the connection, but then decided to try to wrap that string in another object. Doing this doesn't seem to have helped.

Is this some network security issue or am I doing something fundamentally wrong:

client side:


Server Side:
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you call writeObject(), there's no guarantee that all the bits will immediately get sent over the network; some or all of them might be cached. You must call flush() on the stream to force all the data to be sent. This is not a Serialization-specific problem -- in theory it's true for any I/O situation, but especially true in practice for networking.
 
Dave Butterwick
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea...I didn't include that in the code but I am calling flush() on the ObjectOutputStream



So this is probably not my problem.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, let's see the stack trace(s). Do both ends crash or just the reading end?
 
Dave Butterwick
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only errors that come up are on the Listening (server side):
Server Accepted a connection from: /10.20.14.118 on port 6665
Server bound to addr: /10.20.13.199
OIS Available bytes=0, IS Available bytes=0
died on new OIS, ObjectinputStream=java.io.ObjectInputStream@1a46e30 socket=Socket[addr=/10.20.14.118,port=3769,localport=6665], is=java.net.SocketInputStream@3e25a5
isClosed=false, isConnected=true
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.ObjectInputStream$PeekInputStream.peek(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.refill(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.skipBlockData(Unknown Source)
at java.io.ObjectInputStream.skipCustomData(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at mainPack.ServTransaction.run(ServTransaction.java:28)
at java.lang.Thread.run(Unknown Source)

ServTransaction.java:28 is

aString= (String)ois.readObject();
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!