Solved

Open Multiple Internet Sessions

Posted on 2000-04-09
9
493 Views
Last Modified: 2013-11-20
Working With NT, VC6.

I Opened 100 threads
and In Each Thread opened an Internet session.

CInternetSession MySession;
pFile = MySession.OpenURL(url);

I See that 100 threads are running
but somehow in every moment only 2 Sessions are really working.

It seems that NT closes the session whenever it wants...

(I`m using 'netstat' from command prompt)

How can I really open 100 sessions
at the same time?



======================================

int LoadURL(const char* url,char* buffer,int bufferSize)
{
  CInternetSession MySession;
  CStdioFile* pFile = NULL;

   pFile = MySession.OpenURL(url);
   Sleep(10000);
   while (pFile->Read   (buffer,bufferSize) > 0)
   {
     //read file...
   }
     
   delete pFile;
   MySession.Close();
   
}

0
Comment
Question by:TelMic
  • 5
  • 4
9 Comments
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 total points
ID: 2698199
100 threads?  That's absolutely silly; you're wasting more time than you're actually getting work done.  If you've used the default stack size, 100 threads is going to take 100 megs of memory--and that's going to leave you swapping all over the place, unless you have more than 256 megabytes of memory.

Please reconsider your design: you need to do things that will work, and work right--not just throw threads at the problem.

Anyway, that that your client only lets two threads run is completely by design. WININET.DLL is implemented per the HTTP specification, which stipulates that a client should only have two active sessions open against any given server at any time. That's to avoid the client from overpowering the server--something you're bound to do if you ever get those 100 threads of yours running efficiently.

I'm loathe to tell you this because, given your use of 100 threads in your app, you're doubtlessly going to abuse it. But you can hack the registry to get around the limit.

For connections using  HTTP/1.0, you should set the DWORD at HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings\MaxConnectionsPerServer . And for connections using HTTP/1.1, you can set the DWORD at HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings\MaxConnectionsPer1_0Server REG_DWORD (HTTP/1.0 limit) .

Note that this setting effects _all_ apps that use WININET and not just your app, so it's possible you'll break something else on your system by changing the setting.

..B ekiM
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2698203
Why in the world do you sleep 10 seconds after opening the URL?

..B ekiM
0
 

Author Comment

by:TelMic
ID: 2705324
thanks mikeblas,

Thanks,

The only problem is that I get
Sometimes InternetException with Error Code 12002 and others how can I know what does any Error Code Mean...
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2705997
> how can I know what does any Error Code Mean...

Use the ERRLOOK tool.  It's in the Tools menu in the Visual C++ IDE, and it's installed to be on the path after you setup VC++.

Or, use the ReportError() or GetErrorMessage() member functions of CInternetException.

..B ekiM
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:TelMic
ID: 2709448
GetErrorMessage() is not a member
of CInternetException
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2710264
> GetErrorMessage() is not a member
 > of CInternetException

I'm sorry, but it is. I know it is because I'm the one who added it to MFC. If you're using Visual C++ 6.0, see line 2754 of INET.CPP in the MFC\SRC directory.

..B ekiM
0
 

Author Comment

by:TelMic
ID: 2722362
The Error I get is "The operation is timed out",
because I`m sending a lot of request,

Is there is any way to change the TimeOut for OpenURL()?

Thanks.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2729054
Yes. Before calling OpenURL() on the session, call SetOption() on the session object. Use these options to set the time out parameters:

INTERNET_OPTION_CONNECT_RETRIES
INTERNET_OPTION_CONNECT_TIMEOUT
INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT
INTERNET_OPTION_CONTROL_SEND_TIMEOUT
INTERNET_DATA_RECIEVE_TIMEOUT
INTERENT_DATA_SEND_TIMEOUT
INTERNET_OPTION_RECEIVE_TIMEOUT
INTERNET_OPTION_SEND_TIMEOUT

Read the docs to learn what they do; some are meaningful only for cetain protocols. But they're all local to your session, so it's not as if you'll harm another program by changing them.

Please also read Knowledgebase Articles Q224318 and Q176420.

..B ekiM
0
 

Author Comment

by:TelMic
ID: 2741882
Thanks a lot!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now