• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

readObject causing error

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
 
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic