0

Let say A is Server and B is Client. B create a socket b to Server A and ServerSocket.accept() create a corresponding socket a for the client B now if a is closed by Server A but client B haven't closed its socket b and ServerSocket.accept() still running then will ServerSocket.accept() create another socket cfor client B again?

3
  • What do you mean by ServerSocket.accept() is still running? Do you mean it is blocking waiting for a new connection? Jun 3, 2016 at 21:04
  • Your question is ambiguous. The way I read it is as follows: If the SERVER closes its connected socket, but the client doesn't and the server still has an outstanding accept(), will the connection be re-established without the client taking any action. Is that what you intended to ask? Jun 3, 2016 at 21:22
  • @Jim Garrison yes that is what I want to know
    – aukxn
    Jun 3, 2016 at 21:26

1 Answer 1

3

No

When either the Server A or Client B closes the connection, the connection is closed for the sockets on both. The client will need to initialize a new connection in order for a new socket c to be created. ServerSocket.accept() will only return when the client explicitly requests a new connection.

7
  • I have. Since it is a TCP socket, if either side closes the socket, then it closes for both. A new connection will only be created if the client issues another connection request. But if you disagree @JimGarrison, feel free to post your own answer. Jun 3, 2016 at 21:15
  • 1
    The problem is the question is too ambiguous. I read it as asking if the SERVER closes its connected socket, but the client doesn't and the server still has an outstanding accept(), will the connection be re-established without the client taking any action, in which case the answer is no. Jun 3, 2016 at 21:21
  • Given the OP's clarification in a comment, I suggest you edit your answer to match the actual question. Jun 3, 2016 at 21:28
  • @JimGarrison Alright will do. I am still unsure of what is best practices / allowed when editing an answer. Jun 3, 2016 at 21:29
  • 1
    The question is clearer, update your answer without regard for previously wrong information. Make the answer useful for future readers. Jun 3, 2016 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.