Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

InternetSetOption vs CInternetSession::SetOption() and setting timeouts

1 view
Skip to first unread message

jpreble

unread,
Feb 15, 2002, 4:21:55 PM2/15/02
to
I have a couple of questions about setting timeouts when using WinInet
to establish an HTTP connection.

First, what's the preferred way to use WinInet – the APIs (such as
InternetOpen, HttpOpenRequest, HttpSendRequest, InternetSetOption) or
the classes (CInternetSession::GetHttpConnection(),
CHttpConnection::OpenRequest, ChttpFile::SendRequest() )?

Currently, I am using the classes and am trying to set the connect,
send, and receive timeouts but can't get it to work. I've seen the
bug in the MS knowledge base and have upgraded to IE6, but they still
don't work. I've set all 3 timeouts (INTERNET_OPTION_CONNECT_TIMEOUT,
INTERNET_OPTION_SEND_TIMEOUT, and INTERNET_OPTION_RECEIVE_TIMEOUT ) to
be 60 seconds as follows:

session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,60000,0);
session.SetOption(INTERNET_OPTION_SEND_TIMEOUT,60000,0);
session.SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT,60000,0);

I've also set the number of retries to 5 as follows:

session.SetOption(INTERNET_OPTION_CONNECT_RETRIES,5,0);

I assume the retries applies only to the connect, but haven't been
able to verify that.

I've tried calling SetOption method on the CinternetSession object,
ChttpConnection object and the CHttpFile object with the same results.

An interesting observation is that if the server PC is on but the
webserver is disabled (using Netscape Enterprise Server), the
CHttpFile::SendRequest() call throws a CinternetException immediately
(not after the 60 second timeout I am setting). The exception is
12029 (A connection with the server could not be established).
However, if the webserver PC is powered off, CHttpFile::SendRequest()
throws an exception after 20 seconds (regardless of the timeout length
I specify). This time, the exception is 12002 Request has timed out.

In both cases, I thought it was interesting the GetHttpConnection and
OpenRequest calls succeeded – they must not be trying to actually
establish a connection until sendRequest is called.

Anyone have any insight to this madness? Thanks in advance for any
help you can provide.

Brian Combs

unread,
Feb 21, 2002, 10:49:03 AM2/21/02
to
Hello
The different timeouts are the max that we will wait. It could happen
quicker as you are seeing. In the case the server is up but Internet server
is not running we can find the box but it reports that the port is not
open. So we get an error fast. If the box is not running then we have to
take time to try and locate the box. Depending on your network and where
the server is (internet vs intranet) this could take some time. If you want
complete control over the connection see
Q224318 HOWTO: Control Connection Timeout by Creating Second Thread
http://support.microsoft.com/support/kb/articles/q224/3/18.asp

When using HTTP wininet will not try and make the connection to the server
until the HttpSendRequest.

Thanks
Brian [MS]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.

jpreble

unread,
Feb 22, 2002, 1:42:10 PM2/22/02
to
Thanks for your reply, Brian. That clears up a few suspicions I had
in terms of not making the connection until SendRequest, etc. I'll
check out that article you mentioned too.

Also, just to clarify, since CInternetSession::GetHttpConnection() and
CHttpConnection::OpenRequest do not actually make the connection, does
that mean the timeout and retries settings do not apply here, only
when ChttpFile::SendRequest() is called?

Thanks again,
Joe

Brian Combs

unread,
Feb 25, 2002, 9:42:44 AM2/25/02
to
Hello
Yes the timeouts don't start until you do the SendRequest with Http. FTP
works a little different.
0 new messages