Solved

openConnection vs connect

Posted on 2006-07-13
10
394 Views
Last Modified: 2012-06-27
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 ;)
0
Comment
Question by:java_kevin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 17098514
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
0
 
LVL 35

Expert Comment

by:girionis
ID: 17098518
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.
0
 
LVL 35

Expert Comment

by:girionis
ID: 17098523
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:java_kevin
ID: 17098535
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()?
0
 
LVL 35

Expert Comment

by:girionis
ID: 17098559
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).
0
 
LVL 35

Accepted Solution

by:
girionis earned 125 total points
ID: 17098577
> Better call it before you open the connection

I mean call it before you connect using the connect() method.
0
 

Author Comment

by:java_kevin
ID: 17098580
oh.. ok ..thanks.. checking on it..
0
 

Author Comment

by:java_kevin
ID: 17135255
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?
0
 
LVL 35

Expert Comment

by:girionis
ID: 17136214
Nope, it's also applicable to Sun, if you are using jdk.15 and above.
0
 
LVL 35

Expert Comment

by:girionis
ID: 17136221
Sorry, I was talking about the setReadTimeout. I think you are right, the setTimeout is WLS specific only.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example for saving data 19 77
ejb stateless example 2 43
ejb wildfly example 2 74
Java 8 to Java 6 8 33
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question