How does an HttpClient maintain a connection for long time

HI,
Say i have a HttpClient and i set ConnectionTimeOut for it as 10seconds.
Once the connection is established it will stay alive for 10seconds before getting timedOut.
What happens during this 10seconds when we have created HttpConnection. How does the connection stay alive , there must be something going on between client and server so that the connection stays alive.

How much time does it takes to establish an HttpConnection.
Is it a good idea to have HttpConnection established beforehand so as to save time while making an Http Request?
If so how much time should one maintain the HttpConnection.

Thanks
Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

krakatoaCommented:
HTTP is built on top of TCP, and the TCP socket will send keepalives to the other end every so often, up to a couple of hours if there is no higher-level comms activity.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rohit BajajAuthor Commented:
hi
so when we add connection timeout for a http connection what does that means ?
does that timeout apply on tcp socket ?
and some http client also has a readtimeout n write time out
does making an http connection basically means creation of a tcp socket or it does other things also ?
0
krakatoaCommented:
In Java there are only 2 sockets, one for TCP and one for UDP. Forget the latter one for this. So the HttpURLConnection is using a java.net.Socket. Over that socket, you can determine how long a wait should be both to connect - setConnectTimeout() - and to read - setReadTimeOut().

So 'yes' to your third question mark - ?.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Rohit BajajAuthor Commented:
thanks for explanation. i have posted a similar question which uses a restadapter and okhttpclient. if possible please help me out with that.
there what i am not getting is how can i make the http connection before making any request so that it saves time when i need to make any request.
0
krakatoaCommented:
To be frank, I won't be able to assist you with the Restadapter issues. My comments were aimed at the core Java API . . . but if you perhaps post some code, there may be experts who can advise you. If you do not get responses, then I suggest you get a mod onto it to poll the top experts for comments. Good luck though.
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
How much time does it takes to establish an HttpConnection.
Is it a good idea to have HttpConnection established beforehand so as to save time while making an Http Request?
If so how much time should one maintain the HttpConnection.
Hopefully, my comments in your other question have helped your understanding, but to answer the above specifically... The time it takes to establish the connection is very minimal (unless you were communicating over an extremely slow/high latency network). Also, as mentioned here by Krakatoa and by me in your other question, lower levels of the networking stack will attempt to optimize things by keeping the TCP connection alive for a period of time. You don't need to be concerned with this, just let the underlying software handle it for you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.