FOUND SOLUTION (consider this closed and answered since I can't answer my own question before 7 hours). I had left an unnecessary Socket instanciation and it made the clien apps hang. Sorry for bothering all of you for this and thanks for the effort put in helping me run around searching for the issue =) Love you all!
I am getting nuts finding the solution to this "problem". I have an bank simulation application that needs to simulate bank transfers between multiple branches of a bank. I currently use an event bus that dispatches different events objects that are caught by the clients' connector object. If the client listens to the event received, it will call a command object and update whatever it needs to update and so on (just so you get a big picture).
Now, for some reason I cannot understand, my first client instance opens fine, and behaves just as expected, but any client instances opened after the first one will hang in these lines (variables are declared prior to being initialized):
try {
s = new Socket(ip, port);
System.out.println("Creating out stream");
oos = new ObjectOutputStream(s.getOutputStream());
oos.flush();
System.out.println("Flushed data...");
ois = new ObjectInputStream(s.getInputStream());
//Below never gets printed on second client instance *sigh*
System.out.println("HURRAY");
readStream = new ReadEventFromStream(ois, this);
} catch(IOException ioe) {
ioe.printStackTrace();
System.out.println("Can't connect to server.");
System.exit(1);
}
There is no exception thrown, no nothing...the second, third, ... instances launched will just never get past these quite simple lines. Just so you know, the above code is called in the EventBusConnector(...) object instanciated by the client main's function. Here is the ReadEventFromStream class making use of the command objects as stated before:
class ReadEventFromStream extends Thread {
private ObjectInputStream ois;
private EventBusConnector eventBusConn;
public ReadEventFromStream(ObjectInputStream ois, EventBusConnector eventBusConn) {
this.ois = ois;
this.eventBusConn = eventBusConn;
}
@Override
public void run() {
while(true) {
try {
Object o = ois.readObject();
if (eventBusConn.listensToEvent(o)) {
Command command;
if( o instanceof EventBranchListUpdate ) {
EventBranchListUpdate event = (EventBranchListUpdate) o;
command = new UpdateBranchListCommand(event, EventBusConnector.branch);
command.execute();
} else if ( o instanceof EventNewBranch ) {
EventNewBranch event = (EventNewBranch) o;
command = new NewBranchCommand(event, this.eventBusConn);
command.execute();
} else if( o instanceof EventMoneyTransfer ) {
EventMoneyTransfer event = (EventMoneyTransfer) o;
command = new MoneyTransferCommand(event, EventBusConnector.branch);
command.execute();
}
}
}
catch(Exception e) {
e.printStackTrace();
}
}
}
}
So humm...yeah...I've been smashing my heading on this for hours and I really need some help because I'm getting nuts with this. If you need more code I will paste it. Thanks =)
ObjectInputStream's constructor.