Heena Agarwal wrote:I'm relatively new to Socket programming but it looks like you're closing the socket inside the third if statement. Doesn't look like a good idea to me. Is it a logic error or something?
Charles Sexton wrote:
Heena Agarwal wrote:I'm relatively new to Socket programming but it looks like you're closing the socket inside the third if statement. Doesn't look like a good idea to me. Is it a logic error or something?
the socket closes right before the end of while(!done)
Charles Sexton wrote:
Heena Agarwal wrote:
Charles Sexton wrote:
Heena Agarwal wrote:I'm relatively new to Socket programming but it looks like you're closing the socket inside the third if statement. Doesn't look like a good idea to me. Is it a logic error or something?
the socket closes right before the end of while(!done)
Charles Sexton wrote:
Somehow every time I look at your code, it looks to me that you are closing the socket inside the third if loop. But it's possible that I'm not seeing that closing brace somewhere..
Anyway, I'll pass ..
Charles Sexton wrote:This is the error I receive when trying to perform more than one request for the client.....I moved the socket.close(); outside the third if statement but still receive the same error.....I know it has to do something with the while(true) or while(!done) loops.....
java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
Heena Agarwal wrote:
Charles Sexton wrote:This is the error I receive when trying to perform more than one request for the client.....I moved the socket.close(); outside the third if statement but still receive the same error.....I know it has to do something with the while(true) or while(!done) loops.....
java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
Moving socket.close() out of the if loop alone will not solve your problem. That stack trace shows that the connection is closed and you're still trying to receive messages.
So the socket has closed because you are closing it. And what determines that all the requests are processed, the done flag. How are you setting the done flag? It's a local variable I see. So there is no way, an outside entity can set it. Right?
You'd want to set it only after all the requests have completed. Also that is when you'd want to close the connection too. Would that be right?
If so, is your code doing that?
Charles Sexton wrote:
I need the connection to close when all requests are done so you are right. The done Boolean variable is a local variable so their is no way for an outside entity to modify this variable unless it was through the I/O stream correct? If that was the case then when the user closes the client set done = to true.....?
The done Boolean variable is a local variable so their is no way for an outside entity to modify this variable unless it was through the I/O stream correct?
If that was the case then when the user closes the client set done = to true.....?
Heena Agarwal wrote:
Charles Sexton wrote:
I need the connection to close when all requests are done so you are right. The done Boolean variable is a local variable so their is no way for an outside entity to modify this variable unless it was through the I/O stream correct? If that was the case then when the user closes the client set done = to true.....?
Yes. But how do you know all requests are processed and now is the time to close the connection. You need to know that to put the socket.close() at the right place and to ensure that the done flag is set at the right time.
Since it's a local variable, you must have the logic within your method.
I could not understand the following part--
The done Boolean variable is a local variable so their is no way for an outside entity to modify this variable unless it was through the I/O stream correct?
If that was the case then when the user closes the client set done = to true.....?
But done is a local variable. Does your client have any means of setting it?
I'm just saying this by looking at your code. I have no idea of how it is supposed to function. You're the best person for answering that question.
Charles Sexton wrote:
I want the connection to remain open until the GUI is closed. The user closes the GUI by pushing the close button. This would allow the user to make more than one request through the client.
Consider Paul's rocket mass heater. |