Link to home
Start Free TrialLog in
Avatar of java_kevin
java_kevin

asked on

openConnection vs connect

hi guys..

Referring to http://java.sun.com/j2se/1.4.2/docs/api/java/net/URLConnection.html, openConnection() is "Manipulate parameters that affect the connection to the remote resource", while connect() is "Interact with the resource; query header fields and contents."

What's the difference in practical terms? Any analogy to refer?

Does it mean, openConnection is to set the various values of any kind, such as the address, communication format, etc..
while connect() means get ready to output data and/or do work, as the connection has been established?

I'm trying to set the timeout feature, but still trying to get it to work. I had set it after calling openConnection(), and before connect(). And would like to find out the above details. So that, perhaps I can get the idea myself ;)
Avatar of girionis
girionis
Flag of Greece image

Hi java_kevin

First you open a connection by calling openConnection() and then. after the openConnection() sets up the proper parameters, calls the connect() method to connect. The remote site is available then, after the connect() method is called.

Cheers
From the URL: http://java.sun.com/j2se/1.3/docs/api/java/net/URLConnection.html

   1.  The connection object is created by invoking the openConnection method on a URL.
   2. The setup parameters and general request properties are manipulated.
   3. The actual connection to the remote object is made, using the connect method.
   4. The remote object becomes available. The header fields and the contents of the remote object can be accessed.
java_kevin,

> Does it mean, openConnection is to set the various values of any kind,
> such as the address, communication format, etc..
> while connect() means get ready to output data and/or do work, as the
> connection has been established?

Yes
Avatar of java_kevin
java_kevin

ASKER

yup, i saw the URL, but did not understand the stuff they are writing about.

So, does it matter if setReadTimeout is called before openConnection or before connect()?
java_kevin
> So, does it matter if setReadTimeout is called before openConnection
> or before connect()?

Better call it before you open the connection otherwise it might get the default read timeout, since the new value would be set after you connect (if you set it after).
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh.. ok ..thanks.. checking on it..
hey guys,

I just realised that, the settimeout is applicable only to Weblogic 8.1 that I'm using. Sun does not have this feature.. Am I right?
Nope, it's also applicable to Sun, if you are using jdk.15 and above.
Sorry, I was talking about the setReadTimeout. I think you are right, the setTimeout is WLS specific only.