Results 1 to 3 of 3
  1. #1
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default ObjectInputStream wait for readable objects

    Hi all. I have a Server/Client program where they send Objects back and forth. I'm wondering if it is possible to make the ObjectInputStreams block until there is an object that can be read. Currently I get exceptions when I try to run the program because there is nothing in the stream that can be read. Is there any way to do this?

    Thanks in advance,
    Singing Boyo
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Send a dummy object first so that the stream's headers get set up. Subsequent read() calls should then block?
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    ObjectInputStream.readObject() does not block. Period. I don't think that there is anything I can do about it, other than looping endlessly around my try/catch block until I get an object... But that would just seem messy and inefficient. Hopefully I'm wrong...
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Similar Threads

  1. ObjectInputStream does not initialize
    By Singing Boyo in forum New To Java
    Replies: 1
    Last Post: 06-03-2009, 09:11 AM
  2. Reading from ObjectInputStream
    By deepthought015 in forum Networking
    Replies: 8
    Last Post: 04-28-2009, 06:57 PM
  3. Stops when opening ObjectInputStream
    By Norberhuis in forum Networking
    Replies: 4
    Last Post: 01-09-2009, 05:19 PM
  4. Error while converting trace file to readable txt
    By suresh in forum Forum Lobby
    Replies: 1
    Last Post: 12-04-2008, 08:31 AM
  5. Convertin a .DAT file into readable format
    By janakiram.attuluri in forum Advanced Java
    Replies: 1
    Last Post: 12-07-2007, 11:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •