Results 1 to 2 of 2
- 12-09-2009, 03:37 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
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):
Data is sent at sleep() 10k intervals.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); }
This is also done in a thread and is run, as I mentioned before at 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(); }
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.
- 12-09-2009, 03:42 PM #2
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
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
-
Problems writing to an outputstream
By higashij in forum Java ServletReplies: 1Last Post: 09-12-2009, 07:15 PM -
Inconsistent ObjectInput/OutputStreams through Sockets
By Singing Boyo in forum Advanced JavaReplies: 1Last Post: 06-22-2009, 12:43 AM -
Outputstream not streaming.
By dantestein in forum NetworkingReplies: 2Last Post: 03-14-2009, 07:36 AM -
ObjectInput/Output Streams
By Rhesus21 in forum NetworkingReplies: 3Last Post: 07-30-2008, 01:26 AM -
Converting InputStream to OutputStream
By Java Tip in forum Java TipReplies: 1Last Post: 01-11-2008, 10:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks