I'm gonna past a small piece of code that reads data from a socket server coming from flash, and then sends it back to a client, this is the code:
public void run() { try { char charBuffer[] = new char[1]; while(in.read(charBuffer,0,1) != -1) { StringBuffer stringBuffer = new StringBuffer(8192); while(charBuffer[0] != '\0') { System.out.println("loop 2"); stringBuffer.append(charBuffer[0]); in.read(charBuffer, 0 ,1); } System.out.println("Sending message"); server.sendMessage(stringBuffer.toString(),this); } } catch(IOException ioe) { } finally { killClient(); } }
The first while loop checks if it's possible to read data, but it will return false if there is none right? That would mean that the while loop will not execute and it will kill the client, but that doesn't happen until I actually disconnect.
I added a lot of System.out.println statements, what happens is the following:
When client connects, the try block starts
When I send a message, the first while loop executes one time, then the second loop executes the amount of times equal to the amount of characters sent, then it sends the message, and that's where it ends, it never leaves the first while loop until I disconnect! And my brain is killing me! I can't figure out why it would do that...
Can someone help me with this small but annoying thing I have going on? I just can't seem to find the logic why it doesn't execute the finally block