In the client application, I call new Socket(serverIP,serverPort) . As a result, the client application sends a request to the server application to open the socket. Does it open a new stream? I mean, which of the following is true?
The client application sends a request and immediately starts the execution of the following commands (without waiting for a response).
The client sends a request and waits for a response. As soon as a response is received, the client application continues to execute the following commands.
The second case seems more realistic and logical to me. However, I do not understand what will happen if the server does not open the socket, and it does not say that it "does not want" to open the second one (this can happen if the server does not exist or the network does not work). What will happen in this case? Will the server wait forever?
In general, it would be nice if the client knew what was the result of its socket request. For example, I can imagine the following situations:
The socket is opened by the server.
The server refuses to open the socket. Thus, the server exists, it received a request from the client, but it says no.
There is no response from the server.
I know that new Socket(serverIP,serverPort) does not return this information. But this causes exceptions. One of them is "UnkownHostException". When is he cast? When the server does not respond for a while (how long)?
ADDED:
I just found out that an UnknownHostException is thrown to indicate that the host IP cannot be determined. Thus, it is not connected with the situations described above (the server does not respond, the server refuses to open the socket).
source share