Link to home
Start Free TrialLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland 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
Avatar of Rohit Bajaj

ASKER

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 ?
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 - ?.
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.
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.
SOLUTION
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