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.
s = ss.accept();
ois = new ObjectInputStream(s.getInputStream());
temp = (ArrayList<ArrayList>) ois.readObject();
name = (String) ois.readObject();
This is also done in a thread and is run, as I mentioned before at 10k intervals.
s = new Socket(address,port);
oos = new ObjectOutputStream(s.getOutputStream());
public void send()
String clientName = name;
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.