Does Socket open another thread? Does it return something?
- by Roman
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 a socket. Does it start a new thread? I mean which of the following is true?
Client application sends a request and immediately starts to execute following commands (not weighting for the answer).
Client sends the request and weights for the answer. As soon as the answer is obtained, the client application continues to execute following commands.
The second case seems to be more realistic and logical for me. However, I do not understand what happens if the server does not open a socket and it does not say that it does not "want" to open the second (it can happen if the server does not exist or network is broken). What will happen in this case? Will server weight forever?
In general it would be nice for the client to know what is the result of its request for the socket. For example I can imagine the following situations:
The socket is opened by the server.
The server refuses to open a socket. So, server exists, it got the 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 kind of information. But it throws exceptions. One of them is "UnkownHostException". When it is thrown? When the server is not responding for a while (for how long)?
ADDED:
I just found out that UnknownHostException is thrown to indicate that the IP address of a host could not be determined. So, it is unrelated with the above described situations (server is not responding, server refuses to open a socket).