what has been done when URL.openconnection()?
If you read the javadocs for URL.openConnection()
, you'll find:
Returns a
URLConnection
instance that represents a connection to the remote object referred to by the URL.A new instance of
URLConnection
is created every time when invoking theURLStreamHandler.openConnection(URL)
method of the protocol handler for this URL.It should be noted that a
URLConnection
instance does not establish the actual network connection on creation. This will happen only when callingURLConnection.connect()
.
Update
The IP you used in your "random ip" is not valid; it should consist of 4 octets, not 5. The 43ms is probably for: (1) doing a DNS lookup on the non-IP ip (2) printing the stack trace.
Open connection is not like connect
openconnection
does not let you download URL content that's for sure.
You have to call connect
. But not really, the following will explain:
You are not always required to explicitly call the connect
method to initiate the connection. Operations that depend on being connected, like getInputStream
, getOutputStream
, etc, will implicitly perform the connection, if necessary.