Results 1 to 2 of 2
  1. #1
    TheCHaos0 is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default ObjectInput/OutputStream Problems

    Hi,

    I been writing a router simulation program, where I use ObjectOutputStream to write an array and ObjectInputStream to read it from the other end.

    As there are several of these routers in the network and they all connected in a beeline, (A---r1---B---r2---C---r3---D ..etc) we usually get 2 routers trying to connect to one single router (r1 and r3 trying to connect to r2 in this example) and write an array to it via ObjectOutputStream.

    My problem here is, that the middle router will ONLY read the data of the router that has connected first (created InputStream first?). Second router seems to be sending data but middle router never reads it.

    Reading is done like this(in a thread):

    Java Code:
    s = ss.accept();
    ois = new ObjectInputStream(s.getInputStream());
    while(run==true)
    {
    	table.displayTable();
    	temp = (ArrayList<ArrayList>) ois.readObject();
    	name = (String) ois.readObject();
    	table.updateTable(temp,name);
    	this.sleep(5000);
    }
    Data is sent at sleep() 10k intervals.

    Java Code:
    s = new Socket(address,port);
    oos = new ObjectOutputStream(s.getOutputStream());
    oos.flush();
    
    run()
    {
    while(run==true)
    {
    ...
    send();
    ...
    }
    }
    ...
    
    public void send()
    {
        oos.writeObject(table.getTable());
        oos.flush();
        String clientName = name;
        oos.writeObject(clientName);
        oos.flush();
    }
    This is also done in a thread and is run, as I mentioned before at 10k intervals.

    Is there some obvious reason for this? Do ObjectInputStream that are connected to same place somehow block each other? Or perhaps it's something else.

    I did not post the full code, because it's rather big. :) I'm just trying to understand why this happens and what could be done about it, if there's no obvious solution I'll post it up.

    The sending and receive is done in separate Threads. There's 1 Receiver Thread and 2 Sender Threads.

    Thanks in advance.

  2. #2
    TheCHaos0 is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default

    Well it's not Object streams specific (why would it have been). I tried to simply send Strings over with DataOutputStream and read it with DataInputStream. Same result, when 2 clients try to write to 1 server only one that got connected first would has it's data read.

    I would have thought that the when stuff is sent over it goes into a queue in the stream and once it's read it's removed from the stream.

    Can connection from 1 client block from another?

    Hmm wait a second, does servers socket.accept() only supports 1 connection?

Similar Threads

  1. Problems writing to an outputstream
    By higashij in forum Java Servlet
    Replies: 1
    Last Post: 09-12-2009, 07:15 PM
  2. Inconsistent ObjectInput/OutputStreams through Sockets
    By Singing Boyo in forum Advanced Java
    Replies: 1
    Last Post: 06-22-2009, 12:43 AM
  3. Outputstream not streaming.
    By dantestein in forum Networking
    Replies: 2
    Last Post: 03-14-2009, 07:36 AM
  4. ObjectInput/Output Streams
    By Rhesus21 in forum Networking
    Replies: 3
    Last Post: 07-30-2008, 01:26 AM
  5. Converting InputStream to OutputStream
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 01-11-2008, 10:13 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
  •