Valhalla Legends Forums Archive | Java Programming | Sockets problem

AuthorMessageTime
Arta
The class at the end of this post doesn't seem to block (in readObject()) when input isn't available. How might I go about modifying this (or writing something new) that will block until input is available? Or, if I'm totally on the wrong track, what is the correct way to wait for input from a socket?

Thanks in advance!

[code]
/*
* NetObjectReader.java
*
* Created on 01 December 2004, 02:16
*/

import java.net.*;
import java.io.*;

/**
*
* @author  Mike Smith
*/
public class NetObjectReader extends ObjectInputStream

    /** Creates a new instance of NetObjectReader */
    public NetObjectReader(Socket s) throws IOException
    {
        super(s.getInputStream());
    }
   
    public synchronized Object get() throws ClassNotFoundException, IOException
    {
        return readObject();
    }
}
[/code]
December 24, 2004, 2:29 PM
iago
By default, an input stream should block.  Are you sure you have a valid socket?  If you call .read(), does it block?

On a sidenote, when did you change your name to Mike Smith? :)
December 24, 2004, 2:37 PM
Arta
hehe, it's one of the classes provided by the university. Go code reuse!

I'll check that out. I thought it should be blocking!
December 27, 2004, 1:30 PM

Search