Valhalla Legends Archive

Programming => General Programming => Java Programming => Topic started by: Arta on December 24, 2004, 08:29 AM

Title: Sockets problem
Post by: Arta on December 24, 2004, 08:29 AM
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!


/*
* 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();
    }
}
Title: Re: Sockets problem
Post by: iago on December 24, 2004, 08:37 AM
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? :)
Title: Re: Sockets problem
Post by: Arta on December 27, 2004, 07:30 AM
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!