• Welcome to Valhalla Legends Archive.
 

Sockets problem

Started by Arta, December 24, 2004, 08:29 AM

Previous topic - Next topic

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!


/*
* 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();
    }
}

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? :)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


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!