Solved

In Visual C++, how do I connect to an HTTP server via a firewall.

Posted on 2002-04-04
10
239 Views
Last Modified: 2013-12-14
I am developing Visual C++ software that must be able to connect to its server from behind a firewall.  Can anyone out there explain how to do this for SOCKS4, SOCKS5, and any other types of firewall?  Thanks.
0
Comment
Question by:dmcamens
  • 5
  • 3
  • 2
10 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6918525
The WinInet functions should handle that transparently by using the local internet settings - AFAIK there's no need to make any special considerations in your program...
0
 

Author Comment

by:dmcamens
ID: 6918701
I have tried to use the WinInet classes and the problem with them is that they do not support asynchronous HTTP requests, as far as I could tell.  The problem with that is that I have to wait for a request to be completely processed before making another one.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6918742
I'm talking about the WinInet API, not the MFC classes that are wrapped around them - 'WSARecv()' and 'WSASend()' both can handle asynchronous requests...
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:dmcamens
ID: 6918767
How do I get WSARecv and WSASend to allow me to send/recv the requests through a firewall?  Is there another API function to configure the firewall parameters such as the proxy name, port, and protocol?
0
 
LVL 86

Expert Comment

by:jkr
ID: 6918789
>>Is there another API function to configure the firewall
>>parameters such as the proxy name, port, and protocol?

You don't have to - these functions use the local computer's settings. IOW, once you have configured your machine to access the Internet through a firewall, the winsock layer takes care of that. BTW, these are low-level functions operating on sockets. The WinInet API is a bit more high-level, and even withthe MFC wrapper classes you can have requests running asynchronously by using multiple threads...
0
 

Author Comment

by:dmcamens
ID: 6919310
I just tried out the WSA functions.  I am testing it out with WSAAsyncGetHostByName.  I cannot seem to get this to work through a firewall (my machine is configured properly).  When I try to use the MFC classes (see code below), it gets through the firewall but I don't think that I can use multiple threads to make it asynchronous.  I believe I tried that before and the different threads were blocking each other as far as I remember.  Note that I supplied the proxy name into the CInternetSession constructor.  Without that proxy name it does not work.

if (IsDlgButtonChecked(IDC_PROXY_CHECK))
{
    m_proxyEdit.GetWindowText(proxyName);
    dwAccessType = INTERNET_OPEN_TYPE_PROXY;
}
         
iSession = new CInternetSession(
NULL,
1,
dwAccessType,
proxyName.GetBuffer(0),
NULL,
0);                                            
hConnection = iSession->GetHttpConnection(server);
         
pHttpFile = hConnection->OpenRequest("GET",filename.GetBuffer(0));
     
pHttpFile->SendRequest();
nBytes = pHttpFile->Read(httpResponse, 999);
httpResponse[nBytes] = '\0';
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6922170
>>firewall but I don't think that I can use multiple threads to make it asynchronous

Yes you can.  It's pretty straightforward.  For simplicity, create, use, and destroy the session and connection all within the thread proc.  Don't try to pass these objects around unless you want to do extra work.

-- Dan
0
 

Author Comment

by:dmcamens
ID: 6925101
Ok, I see what you mean now.  I was trying to use the same CInternetSession object in each thread to take advantage of the fact that HTTP can keep a session going instead of connecting and disconnecting for each and every request.  That may be a performance hit but we may be able to live with it.  Do you know a way to still take advantage of the "keep alive" functionality?
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 200 total points
ID: 6926269
I'm not sure about 'keep alive' I think it has to do with server-side handling.

On the client side, if you never close the session, then the session remains 'live' and you can reuse it to go to the same server again and again with OpenURL() et. al.  

-- Dan
0
 

Author Comment

by:dmcamens
ID: 6926276
Dan,

Thanks for your help.  I think I will go with the multithreading WinInet classes since the prototype I built seems to be working through the firewall now.

Thanks,
-Doug
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

778 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