New Socket(host,port) does not open a new thread. It starts a synchronous tcp connection establishment. This may take a few seconds or time out after some default timeout.
New Socket(host,port) does not open a new thread. It starts a synchronous tcp connection establishment. This may take a few seconds or time out after some default timeout.
If the server refuses to accept the connection, or the client can't resolve the ip of the host or access the server (unreachable) an appropriate exception is thrown. (if you want to control the timeout use the default constructor and the connect(SocketAddress endpoint, int timeout) method).
Well I see nothing in the documentation saying that it creates a new thread, so the answer to your question is NO.
Not sure if it opens new Thread, but I know it blocks until: Successfully opens Exception occurs Timeout You can control the timeout limit, other than that, you will have to wait for an answer.
Server is not responding maybe means before timeout the server dosen't response the request. Server refuses to open a socket maybe means there hasn't any server process listen listen on this port,the port dosen't open.
The statement new Socket(ip, port) doesn't create a new thread. It just creates a client socket object. For you to send and receive data you have to use getInputStream/getOutputStream methods on the client socket and then do a read/write operation.OutStream.write() usually behaves like a non-blocking call whereas inStream.read() is a blocking call.
Ideally, client sockets are created in a separate thread so that the main process would continue to go ahead without waiting for socket related IO operations. I would recommend to follow similar thing by creating a new thread and assigning the client socket to that thread.
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 wait forever?
What server? If the server does not exist there is no server so how can it wait forever? If the network was broken how would the server ever know about the connection attempt?
Neither of these cases is 'the server not wanting to open a socket'. In neither case will the server wait forever. Neither will the client.
There is a default connection timeout of about a minute, platform-dependent, but you can shorten it as described in one of the other answers. In general it would be nice for the client to know what is the result of its request for the socket. It does.
Either the code continues or an IOException is thrown. Which IOException it is indicates what went wrong.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.