Wheeew,
Man this client server architecture thing sure is confusing... Im on hour 12 now.
I tested and tested and came to find out that it really is hanging in the try statements
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public void run() { int Rnd = 0; while(true){ try { if(client_socket1 == null){ client_socket1 = listen_socket.accept(); if(client_socket1 != null){ System.out.println("Client1 has connected"); } } } catch(IOException e) { fail(e, "Exception while listening for connections"); } try{ if(client_socket2 == null){ client_socket2 = listen_socket.accept(); if(client_socket2 != null){ System.out.println("Client2 has connected."); TTTConn conn1 = new TTTConn(client_socket1, client_socket2); } } } catch(IOException e) { fail(e, "Exception while listening for connections"); } Rnd = Rnd + 1; System.out.println("Rnd: "+Rnd); } } |
The above code works and prints Client1 has connected when the first user connects, then Client2 has connected when the second user connects. The Out.PrintLn doesnt happen until 2 users have connected. I wasnt prepared for that.
But, this is not the direction I was going for, so Im looking at more stuff, hehehehe. Im looking at a chat server that consistantly accepts connections and deletes them in unused. I like this style a bit better.
Thanks for the help though