I’m using the HttpURLConnection to open connections to web pages. I call the connect() method to open the connection.
I not found an isConnected() method.
I need to know when the connection was established with the server. I need this because I tryinf to found a fast way to open multiple connections. One object open connections and another do some processing with the connections that established the communication with the server.
I want to let the processor always busy.
Not sure why you would need that information.
You should not care since once you call
connect()you can start retrieving the response e.g.Assuming of course you have send all your request to the output stream.
The
HttpURLConnectionunder the hood knows if it is already connected to the server and the implementation reuses the connection (transparent to you).Now, having said that to answer your question, I think that the only way to know if the
HttpURLConnection‘s state is connected to the server, is to callopenConnection()a second time in the sameHttpURLConnectionobject.If it is already connected it will throw a relevant exception complaining that it is already connected something like:
IllegalStateException("Already connected");.At that point you know that the
HttpURLConnectionis connected