Solved

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

Posted on 2002-04-04
10
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

632 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